mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-15 05:22:35 +02:00
Add nativeScriptJob errors
This commit is contained in:
parent
e8aa2e6de9
commit
e997a194a4
@ -893,13 +893,21 @@ Tomahawk.NativeScriptJobManager = {
|
||||
Tomahawk.invokeNativeScriptJob(requestId, methodName, encodeParamsToNativeFunctions(params));;
|
||||
return deferred.promise;
|
||||
},
|
||||
reportNativeScriptJobResult: function (requestId, result) {
|
||||
reportNativeScriptJobResult: function(requestId, result) {
|
||||
var deferred = this.deferreds[requestId];
|
||||
if (!deferred) {
|
||||
Tomahawk.log("Deferred object with the given requestId is not present!");
|
||||
}
|
||||
deferred.resolve(result);
|
||||
delete this.deferreds[requestId];
|
||||
},
|
||||
reportNativeScriptJobError: function(requestId, error) {
|
||||
var deferred = this.deferreds[requestId];
|
||||
if (!deferred) {
|
||||
console.log("Deferred object with the given requestId is not present!");
|
||||
}
|
||||
deferred.reject(error);
|
||||
delete this.deferreds[requestId];
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -187,6 +187,25 @@ JSAccount::reportNativeScriptJobResult( int resultId, const QVariantMap& result
|
||||
evaluateJavaScript( eval );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
JSAccount::reportNativeScriptJobError( int resultId, const QVariantMap& error )
|
||||
{
|
||||
QString eval = QString(
|
||||
"Tomahawk.NativeScriptJobManager.reportNativeScriptJobError("
|
||||
"%1," // requestId
|
||||
"%2" // results
|
||||
");"
|
||||
).arg( resultId )
|
||||
.arg( serializeQVariantMap( error ) );
|
||||
|
||||
// Remove when new scripting api turned out to work reliably
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << eval;
|
||||
|
||||
evaluateJavaScript( eval );
|
||||
}
|
||||
|
||||
|
||||
QVariant
|
||||
JSAccount::evaluateJavaScriptInternal( const QString& scriptSource )
|
||||
{
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
static QString serializeQVariantMap(const QVariantMap& map);
|
||||
|
||||
void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) override;
|
||||
void reportNativeScriptJobError( int resultId, const QVariantMap& error ) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -635,8 +635,11 @@ JSResolverHelper::invokeNativeScriptJob( int requestId, const QString& methodNam
|
||||
if ( methodName == "httpRequest" ) {
|
||||
nativeAsyncRequest( requestId, params );
|
||||
} else {
|
||||
// TODO: make promise reject instead
|
||||
Q_ASSERT_X(false, "invokeNativeScriptJob", "NativeScriptJob methodName was not found");
|
||||
QVariantMap error;
|
||||
error["message"] = "NativeScriptJob methodName was not found";
|
||||
error["name"] = "method_was_not_found";
|
||||
|
||||
m_resolver->d_func()->scriptAccount->reportNativeScriptJobError( requestId, error );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,7 @@ public:
|
||||
void unregisterScriptPlugin( const QString& type, const QString& objectId );
|
||||
|
||||
virtual void reportNativeScriptJobResult( int resultId, const QVariantMap& result ) = 0;
|
||||
virtual void reportNativeScriptJobError( int resultId, const QVariantMap& error ) = 0;
|
||||
|
||||
virtual void scriptPluginFactory( const QString& type, const scriptobject_ptr& object );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user