diff --git a/app/langs/zh-CN.json b/app/langs/zh-CN.json index 3eac07f..f15d9e8 100644 --- a/app/langs/zh-CN.json +++ b/app/langs/zh-CN.json @@ -122,6 +122,11 @@ "settings.file-count": "({{count}} 个文件)", "settings.total-count": "(共计: {{count}}个)" }, + "rpc": { + "error": { + "Unauthorized": "认证失败!" + } + }, "options": { "dir.name": "下载路径", "dir.description": "", diff --git a/app/scripts/config/language-default.js b/app/scripts/config/language-default.js index a75b335..0eddb95 100644 --- a/app/scripts/config/language-default.js +++ b/app/scripts/config/language-default.js @@ -126,6 +126,11 @@ 'settings.file-count': '({{count}} Files)', 'settings.total-count': '(Total Count: {{count}})' }, + 'rpc': { + 'error': { + 'Unauthorized': 'Authorization Failed!' + } + }, 'options': { 'dir.name': 'Download Path', 'dir.description': '', diff --git a/app/scripts/services/aria2HttpRpcService.js b/app/scripts/services/aria2HttpRpcService.js index e4e235f..a104743 100644 --- a/app/scripts/services/aria2HttpRpcService.js +++ b/app/scripts/services/aria2HttpRpcService.js @@ -29,6 +29,10 @@ return; } + if (context.errorCallback) { + context.errorCallback(data.error); + } + if (context.callback) { context.callback(data.error); } diff --git a/app/scripts/services/aria2RpcService.js b/app/scripts/services/aria2RpcService.js index c0a629a..0cb83aa 100644 --- a/app/scripts/services/aria2RpcService.js +++ b/app/scripts/services/aria2RpcService.js @@ -38,6 +38,19 @@ 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') { return aria2WebSocketRpcService.request(context); } else { diff --git a/app/scripts/services/aria2WebSocketRpcService.js b/app/scripts/services/aria2WebSocketRpcService.js index a3a1ae2..63ca788 100644 --- a/app/scripts/services/aria2WebSocketRpcService.js +++ b/app/scripts/services/aria2WebSocketRpcService.js @@ -34,18 +34,21 @@ } var context = state.context; - var callbackMethod = context.callback; state.deferred.resolve({ success: true, context: context }); - if (callbackMethod) { + if (content.error && context.errorCallback) { + context.errorCallback(content.error); + } + + if (context.callback) { if (content.result) { - callbackMethod(content.result); + context.callback(content.result); } else if (content.error) { - callbackMethod(content.error); + context.callback(content.error); } }