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
27 _proxyModel.sort(0);27 _proxyModel.sort(0);
28}28}
29 29
30QString 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
51void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJSValue callback) {30void AssetMappingsScriptingInterface::setMapping(QString path, QString hash, QJSValue callback) {
52 auto assetClient = DependencyManager::get<AssetClient>();31 auto assetClient = DependencyManager::get<AssetClient>();
53 auto request = assetClient->createSetMappingRequest(path, hash);32 auto request = assetClient->createSetMappingRequest(path, hash);
54 33
55 connect(request, &SetMappingRequest::finished, this, [this, callback](SetMappingRequest* request) mutable {34 connect(request, &SetMappingRequest::finished, this, [this, callback](SetMappingRequest* request) mutable {
56 if (callback.isCallable()) {35 if (callback.isCallable()) {
57 QJSValueList args { uint8_t(request->getError()), request->getPath() };36 QJSValueList args { request->getErrorString(), request->getPath() };
58 callback.call(args);37 callback.call(args);
59 }38 }
60 39
@@ -70,7 +49,7 @@ void AssetMappingsScriptingInterface::getMapping(QString path, QJSValue callback · 9 unmodified lines
70 49
71 connect(request, &GetMappingRequest::finished, this, [this, callback](GetMappingRequest* request) mutable {50 connect(request, &GetMappingRequest::finished, this, [this, callback](GetMappingRequest* request) mutable {
72 if (callback.isCallable()) {51 if (callback.isCallable()) {
73 QJSValueList args { uint8_t(request->getError()) };52 QJSValueList args { request->getErrorString() };
74 callback.call(args);53 callback.call(args);
75 }54 }
76 55
@@ -108,7 +87,7 @@ void AssetMappingsScriptingInterface::uploadFile(QString path, QString mapping, · 31 unmodified lines
108 QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {87 QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
109 if (upload->getError() != AssetUpload::NoError) {88 if (upload->getError() != AssetUpload::NoError) {
110 if (callback.isCallable()) {89 if (callback.isCallable()) {
111 QJSValueList args { uint8_t(upload->getError()) };90 QJSValueList args { upload->getErrorString() };
112 callback.call(args);91 callback.call(args);
113 }92 }
114 } else {93 } else {
@@ -127,7 +106,7 @@ void AssetMappingsScriptingInterface::deleteMappings(QStringList paths, QJSValue · 12 unmodified lines
127 106
128 connect(request, &DeleteMappingsRequest::finished, this, [this, callback](DeleteMappingsRequest* request) mutable {107 connect(request, &DeleteMappingsRequest::finished, this, [this, callback](DeleteMappingsRequest* request) mutable {
129 if (callback.isCallable()) {108 if (callback.isCallable()) {
130 QJSValueList args { uint8_t(request->getError()) };109 QJSValueList args { request->getErrorString() };
131 callback.call(args);110 callback.call(args);
132 }111 }
133 112
@@ -150,7 +129,7 @@ void AssetMappingsScriptingInterface::getAllMappings(QJSValue callback) { · 16 unmodified lines
150 }129 }
151 130
152 if (callback.isCallable()) {131 if (callback.isCallable()) {
153 QJSValueList args { uint8_t(request->getError()), map };132 QJSValueList args { request->getErrorString(), map };
154 callback.call(args);133 callback.call(args);
155 }134 }
156 135
@@ -166,7 +145,7 @@ void AssetMappingsScriptingInterface::renameMapping(QString oldPath, QString new · 9 unmodified lines
166 145
167 connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable {146 connect(request, &RenameMappingRequest::finished, this, [this, callback](RenameMappingRequest* request) mutable {
168 if (callback.isCallable()) {147 if (callback.isCallable()) {
169 QJSValueList args { uint8_t(request->getError()) };148 QJSValueList args { request->getErrorString() };
170 callback.call(args);149 callback.call(args);
171 }150 }
172 151
@@ -293,7 +272,7 @@ void AssetMappingModel::refresh() { · 120 unmodified lines
293 }272 }
294 }273 }
295 } else {274 } else {
296 emit errorGettingMappings(static_cast<int>(request->getError()));275 emit errorGettingMappings(request->getErrorString());
297 }276 }
298 });277 });
299 278