support show rpc error message

This commit is contained in:
MaysWind 2016-06-04 17:08:42 +08:00
parent 53a4fc0403
commit 080a50a772
5 changed files with 34 additions and 4 deletions

View file

@ -122,6 +122,11 @@
"settings.file-count": "({{count}} 个文件)", "settings.file-count": "({{count}} 个文件)",
"settings.total-count": "(共计: {{count}}个)" "settings.total-count": "(共计: {{count}}个)"
}, },
"rpc": {
"error": {
"Unauthorized": "认证失败!"
}
},
"options": { "options": {
"dir.name": "下载路径", "dir.name": "下载路径",
"dir.description": "", "dir.description": "",

View file

@ -126,6 +126,11 @@
'settings.file-count': '({{count}} Files)', 'settings.file-count': '({{count}} Files)',
'settings.total-count': '(Total Count: {{count}})' 'settings.total-count': '(Total Count: {{count}})'
}, },
'rpc': {
'error': {
'Unauthorized': 'Authorization Failed!'
}
},
'options': { 'options': {
'dir.name': 'Download Path', 'dir.name': 'Download Path',
'dir.description': '', 'dir.description': '',

View file

@ -29,6 +29,10 @@
return; return;
} }
if (context.errorCallback) {
context.errorCallback(data.error);
}
if (context.callback) { if (context.callback) {
context.callback(data.error); context.callback(data.error);
} }

View file

@ -38,6 +38,19 @@
context.requestBody.params = finalParams; context.requestBody.params = finalParams;
} }
if (!context.silent) {
context.errorCallback = function (error) {
if (!error || !error.message) {
return;
}
if (error.message == 'Unauthorized') {
ariaNgCommonService.alert('rpc.error.' + error.message);
return;
}
}
}
if (protocol == 'ws' || protocol == 'wss') { if (protocol == 'ws' || protocol == 'wss') {
return aria2WebSocketRpcService.request(context); return aria2WebSocketRpcService.request(context);
} else { } else {

View file

@ -34,18 +34,21 @@
} }
var context = state.context; var context = state.context;
var callbackMethod = context.callback;
state.deferred.resolve({ state.deferred.resolve({
success: true, success: true,
context: context context: context
}); });
if (callbackMethod) { if (content.error && context.errorCallback) {
context.errorCallback(content.error);
}
if (context.callback) {
if (content.result) { if (content.result) {
callbackMethod(content.result); context.callback(content.result);
} else if (content.error) { } else if (content.error) {
callbackMethod(content.error); context.callback(content.error);
} }
} }