error handling

This commit is contained in:
Seth Alves 2018-01-15 10:48:12 -08:00
parent 3e7d303661
commit 76048f3c30
2 changed files with 7 additions and 4 deletions

View file

@ -61,13 +61,15 @@ void AssetScriptingInterface::getMapping(QString path, QScriptValue callback) {
auto result = request->getError();
if (callback.isFunction()) {
if (result == GetMappingRequest::NotFound) {
QScriptValueList args { "" };
QScriptValueList args { "", true };
callback.call(_engine->currentContext()->thisObject(), args);
} else if (result == GetMappingRequest::NoError) {
QScriptValueList args { request->getHash() };
QScriptValueList args { request->getHash(), true };
callback.call(_engine->currentContext()->thisObject(), args);
} else {
qCDebug(scriptengine) << "error -- " << request->getError() << " -- " << request->getErrorString();
QScriptValueList args { "", false };
callback.call(_engine->currentContext()->thisObject(), args);
}
request->deleteLater();
}

View file

@ -85,9 +85,10 @@ public:
*/
/**jsdoc
* Called when getMapping is complete
* Called when getMapping is complete.
* @callback Assets~getMappingCallback
* @param {string} assetID
* @param assetID {string} hash value if found, else an empty string
* @param success {boolean} false for errors other than "not found", else true
*/
Q_INVOKABLE void getMapping(QString path, QScriptValue callback);