From 080a50a772b6143042d274f8c3c9c50a8eae250b Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 4 Jun 2016 17:08:42 +0800 Subject: [PATCH] support show rpc error message --- app/langs/zh-CN.json | 5 +++++ app/scripts/config/language-default.js | 5 +++++ app/scripts/services/aria2HttpRpcService.js | 4 ++++ app/scripts/services/aria2RpcService.js | 13 +++++++++++++ app/scripts/services/aria2WebSocketRpcService.js | 11 +++++++---- 5 files changed, 34 insertions(+), 4 deletions(-) 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); } }