show error dialog when failed to init websocket

This commit is contained in:
MaysWind 2017-10-08 15:37:54 +08:00
parent 0bf8c725a4
commit ccac9d82a2
5 changed files with 47 additions and 21 deletions

View file

@ -199,6 +199,7 @@ RPC host cannot be empty!=RPC 主机不能为空!
RPC secret is not base64 encoded!=RPC 密钥不是 Base64 编码后的字符串! RPC secret is not base64 encoded!=RPC 密钥不是 Base64 编码后的字符串!
URL is not base64 encoded!=指定 URL 不是 Base64 编码后的字符串! URL is not base64 encoded!=指定 URL 不是 Base64 编码后的字符串!
Tap to configure and get started with AriaNg.=您还没有进行过设置, 点击这里进行设置. Tap to configure and get started with AriaNg.=您还没有进行过设置, 点击这里进行设置.
Cannot initialize WebSocket!=无法初始化 WebSocket!
[error] [error]
unknown=未知错误. unknown=未知错误.

View file

@ -199,6 +199,7 @@ RPC host cannot be empty!=RPC 主機不能為空!
RPC secret is not base64 encoded!=RPC 密鑰不是 Base64 編碼後的字元串! RPC secret is not base64 encoded!=RPC 密鑰不是 Base64 編碼後的字元串!
URL is not base64 encoded!=指定 URL 不是 Base64 編碼後的字元串! URL is not base64 encoded!=指定 URL 不是 Base64 編碼後的字元串!
Tap to configure and get started with AriaNg.=您還沒有進行過設置, 點擊這裡進行設置. Tap to configure and get started with AriaNg.=您還沒有進行過設置, 點擊這裡進行設置.
Cannot initialize WebSocket!=無法初始化 WebSocket!
[error] [error]
unknown=未知錯誤. unknown=未知錯誤.

View file

@ -1,7 +1,9 @@
(function () { (function () {
'use strict'; 'use strict';
angular.module('ariaNg').config(['$translateProvider', 'localStorageServiceProvider', 'NotificationProvider', 'ariaNgConstants', 'ariaNgLanguages', function ($translateProvider, localStorageServiceProvider, NotificationProvider, ariaNgConstants, ariaNgLanguages) { angular.module('ariaNg').config(['$qProvider', '$translateProvider', 'localStorageServiceProvider', 'NotificationProvider', 'ariaNgConstants', 'ariaNgLanguages', function ($qProvider, $translateProvider, localStorageServiceProvider, NotificationProvider, ariaNgConstants, ariaNgLanguages) {
$qProvider.errorOnUnhandledRejections(false);
localStorageServiceProvider localStorageServiceProvider
.setPrefix(ariaNgConstants.appPrefix) .setPrefix(ariaNgConstants.appPrefix)
.setStorageType('localStorage') .setStorageType('localStorage')

View file

@ -203,6 +203,7 @@
'RPC secret is not base64 encoded!': 'RPC secret is not base64 encoded!', 'RPC secret is not base64 encoded!': 'RPC secret is not base64 encoded!',
'URL is not base64 encoded!': 'URL is not base64 encoded!', 'URL is not base64 encoded!': 'URL is not base64 encoded!',
'Tap to configure and get started with AriaNg.': 'Tap to configure and get started with AriaNg.', 'Tap to configure and get started with AriaNg.': 'Tap to configure and get started with AriaNg.',
'Cannot initialize WebSocket!': 'Cannot initialize WebSocket!',
'error': { 'error': {
'unknown': 'Unknown error occurred.', 'unknown': 'Unknown error occurred.',
'operation.timeout': 'Operation timed out.', 'operation.timeout': 'Operation timed out.',

View file

@ -29,7 +29,7 @@
}); });
if (content.result && context.successCallback) { if (content.result && context.successCallback) {
ariaNgLogService.debug('[aria2WebSocketRpcService.request] response uccess', content); ariaNgLogService.debug('[aria2WebSocketRpcService.request] response success', content);
context.successCallback(context.id, content.result); context.successCallback(context.id, content.result);
} }
@ -65,6 +65,7 @@
var getSocketClient = function () { var getSocketClient = function () {
if (socketClient === null) { if (socketClient === null) {
try {
socketClient = $websocket(rpcUrl); socketClient = $websocket(rpcUrl);
socketClient.onMessage(function (message) { socketClient.onMessage(function (message) {
@ -84,9 +85,19 @@
processEventCallback(content); processEventCallback(content);
} }
}); });
} catch (ex) {
return {
success: false,
error: 'Cannot initialize WebSocket!',
exception: ex
}
}
} }
return socketClient; return {
success: true,
instance: socketClient
};
}; };
return { return {
@ -108,7 +119,17 @@
deferred: deferred deferred: deferred
}; };
client.send(requestBody); if (client.instance) {
client.instance.send(requestBody);
} else {
deferred.reject({
success: false,
context: context
});
ariaNgLogService.debug('[aria2WebSocketRpcService.request] client error', client);
context.errorCallback(context.id, { message: client.error });
}
return deferred.promise; return deferred.promise;
}, },