History

fix error handling for diff request types

Stephen Birarda committed 10 years ago

Commit e51aede1 parent 9522c2d6 files · +40 −38Browse files

Showing the changes to interface/src/scripting/AssetMappingsScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

interface/src/scripting/AssetMappingsScriptingInterface.cpp+7−28
@@ -27,34 +27,13 @@ AssetMappingsScriptingInterface::AssetMappingsScriptingInterface() { · 26 unmodified lines
2727 _proxyModel.sort(0);
2828 }
2929
30−QString AssetMappingsScriptingInterface::getErrorString(int errorCode) const {
31− switch (errorCode) {
32− case MappingRequest::NoError:
33− return "No error";
34− case MappingRequest::NotFound:
35− return "Asset not found";
36− case MappingRequest::NetworkError:
37− return "Unable to communicate with Asset Server";
38− case MappingRequest::PermissionDenied:
39− return "Permission denied";
40− case MappingRequest::InvalidPath:
41− return "Path is invalid";
42− case MappingRequest::InvalidHash:
43− return "Hash is invalid";
44− case MappingRequest::UnknownError:
45− return "Asset Server internal error";
46− default:
47− return QString();
48− }
49−}
50−
5130 void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJSValue callback) {
5231 auto assetClient = DependencyManager::get<AssetClient>();
5332 auto request = assetClient->createSetMappingRequest(path, hash);
5433
5534 connect(request, &SetMappingRequest::finished, this, [this, callback](SetMappingRequest* request) mutable {
5635 if (callback.isCallable()) {
57− QJSValueList args { uint8_t(request->getError()), request->getPath() };
36+ QJSValueList args { request->getErrorString(), request->getPath() };
5837 callback.call(args);
5938 }
6039
@@ -70,7 +49,7 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback · 9 unmodified lines
7049
7150 connect(request, &GetMappingRequest::finished, this, [this, callback](GetMappingRequest* request) mutable {
7251 if (callback.isCallable()) {
73− QJSValueList args { uint8_t(request->getError()) };
52+ QJSValueList args { request->getErrorString() };
7453 callback.call(args);
7554 }
7655
@@ -108,7 +87,7 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, · 31 unmodified lines
10887 QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
10988 if (upload->getError() != AssetUpload::NoError) {
11089 if (callback.isCallable()) {
111− QJSValueList args { uint8_t(upload->getError()) };
90+ QJSValueList args { upload->getErrorString() };
11291 callback.call(args);
11392 }
11493 } else {
@@ -127,7 +106,7 @@ void AssetMappingsScriptingInterface::deleteMappings(QStringList paths, QJSValue · 12 unmodified lines
127106
128107 connect(request, &DeleteMappingsRequest::finished, this, [this, callback](DeleteMappingsRequest* request) mutable {
129108 if (callback.isCallable()) {
130− QJSValueList args { uint8_t(request->getError()) };
109+ QJSValueList args { request->getErrorString() };
131110 callback.call(args);
132111 }
133112
@@ -150,7 +129,7 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) { · 16 unmodified lines
150129 }
151130
152131 if (callback.isCallable()) {
153− QJSValueList args { uint8_t(request->getError()), map };
132+ QJSValueList args { request->getErrorString(), map };
154133 callback.call(args);
155134 }
156135
@@ -166,7 +145,7 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new · 9 unmodified lines
166145
167146 connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable {
168147 if (callback.isCallable()) {
169− QJSValueList args { uint8_t(request->getError()) };
148+ QJSValueList args { request->getErrorString() };
170149 callback.call(args);
171150 }
172151
@@ -293,7 +272,7 @@ void AssetMappingModel::refresh() { · 120 unmodified lines
293272 }
294273 }
295274 } else {
296− emit errorGettingMappings(static_cast<int>(request->getError()));
275+ emit errorGettingMappings(request->getErrorString());
297276 }
298277 });
299278