show error dialog when failed to init websocket

master
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 编码后的字符串!
URL is not base64 encoded!=指定 URL 不是 Base64 编码后的字符串!
Tap to configure and get started with AriaNg.=您还没有进行过设置, 点击这里进行设置.
Cannot initialize WebSocket!=无法初始化 WebSocket!
[error]
unknown=未知错误.

View File

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

View File

@ -1,7 +1,9 @@
(function () {
'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
.setPrefix(ariaNgConstants.appPrefix)
.setStorageType('localStorage')

View File

@ -203,6 +203,7 @@
'RPC secret is not base64 encoded!': 'RPC secret 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.',
'Cannot initialize WebSocket!': 'Cannot initialize WebSocket!',
'error': {
'unknown': 'Unknown error occurred.',
'operation.timeout': 'Operation timed out.',

View File

@ -29,7 +29,7 @@
});
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);
}
@ -65,28 +65,39 @@
var getSocketClient = function () {
if (socketClient === null) {
socketClient = $websocket(rpcUrl);
try {
socketClient = $websocket(rpcUrl);
socketClient.onMessage(function (message) {
if (!message || !message.data) {
return;
socketClient.onMessage(function (message) {
if (!message || !message.data) {
return;
}
var content = angular.fromJson(message.data);
if (!content) {
return;
}
if (content.id) {
processMethodCallback(content);
} else if (content.method) {
processEventCallback(content);
}
});
} catch (ex) {
return {
success: false,
error: 'Cannot initialize WebSocket!',
exception: ex
}
var content = angular.fromJson(message.data);
if (!content) {
return;
}
if (content.id) {
processMethodCallback(content);
} else if (content.method) {
processEventCallback(content);
}
});
}
}
return socketClient;
return {
success: true,
instance: socketClient
};
};
return {
@ -108,7 +119,17 @@
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;
},