Commit 0b664e9d93b7020e4268fa7006a5d01a96f0ecfb

Authored by Igor Kulikov
1 parent 4094996e

Improve WS errors handling.

... ... @@ -263,7 +263,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
263 263 if (regularUserSessions.size() < maxSessionsPerRegularUser) {
264 264 regularUserSessions.add(sessionId);
265 265 } else {
266   - log.info("[{}][{}][{}] Failed to start session. Max user sessions limit reached"
  266 + log.info("[{}][{}][{}] Failed to start session. Max regular user sessions limit reached"
267 267 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId);
268 268 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max regular user sessions limit reached"));
269 269 return false;
... ... @@ -276,7 +276,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
276 276 if (publicUserSessions.size() < maxSessionsPerPublicUser) {
277 277 publicUserSessions.add(sessionId);
278 278 } else {
279   - log.info("[{}][{}][{}] Failed to start session. Max user sessions limit reached"
  279 + log.info("[{}][{}][{}] Failed to start session. Max public user sessions limit reached"
280 280 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId);
281 281 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max public user sessions limit reached"));
282 282 return false;
... ...
... ... @@ -266,7 +266,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
266 266 } else if (customerSessions.size() < maxSubscriptionsPerCustomer) {
267 267 customerSessions.add(subId);
268 268 } else {
269   - log.info("[{}][{}][{}] Failed to start subscription. Max customer sessions limit reached"
  269 + log.info("[{}][{}][{}] Failed to start subscription. Max customer subscriptions limit reached"
270 270 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
271 271 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max customer subscriptions limit reached"));
272 272 return false;
... ... @@ -279,7 +279,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
279 279 if (regularUserSessions.size() < maxSubscriptionsPerRegularUser) {
280 280 regularUserSessions.add(subId);
281 281 } else {
282   - log.info("[{}][{}][{}] Failed to start subscription. Max user sessions limit reached"
  282 + log.info("[{}][{}][{}] Failed to start subscription. Max regular user subscriptions limit reached"
283 283 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
284 284 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max regular user subscriptions limit reached"));
285 285 return false;
... ... @@ -292,7 +292,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
292 292 if (publicUserSessions.size() < maxSubscriptionsPerPublicUser) {
293 293 publicUserSessions.add(subId);
294 294 } else {
295   - log.info("[{}][{}][{}] Failed to start subscription. Max user sessions limit reached"
  295 + log.info("[{}][{}][{}] Failed to start subscription. Max public user subscriptions limit reached"
296 296 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
297 297 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max public user subscriptions limit reached"));
298 298 return false;
... ...
... ... @@ -26,7 +26,7 @@ const WS_IDLE_TIMEOUT = 90000;
26 26 const MAX_PUBLISH_COMMANDS = 10;
27 27
28 28 /*@ngInject*/
29   -function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, toast, types, userService) {
  29 +function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, $mdUtil, toast, types, userService) {
30 30
31 31 var isOpening = false,
32 32 isOpened = false,
... ... @@ -111,7 +111,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to
111 111 }
112 112 }
113 113
114   - function onError (/*message*/) {
  114 + function onError (errorEvent) {
  115 + if (errorEvent) {
  116 + showWsError(0, errorEvent);
  117 + }
115 118 isOpening = false;
116 119 }
117 120
... ... @@ -137,7 +140,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to
137 140 }
138 141 }
139 142
140   - function onClose () {
  143 + function onClose (closeEvent) {
  144 + if (closeEvent && closeEvent.code > 1000) {
  145 + showWsError(closeEvent.code, closeEvent.reason);
  146 + }
141 147 isOpening = false;
142 148 isOpened = false;
143 149 if (isActive) {
... ... @@ -191,7 +197,9 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to
191 197 } else {
192 198 message += "error code - " + errorCode + ".";
193 199 }
194   - toast.showError(message);
  200 + $mdUtil.nextTick(function () {
  201 + toast.showError(message);
  202 + });
195 203 }
196 204
197 205 function fetchKeys(subscriptionId) {
... ...
... ... @@ -16,18 +16,21 @@
16 16
17 17 md-toast.tb-info-toast .md-toast-content {
18 18 height: 100%;
  19 + max-height: 100%;
19 20 padding: 18px;
20 21 font-size: 18px;
21 22 }
22 23
23 24 md-toast.tb-success-toast .md-toast-content {
24 25 height: 100%;
  26 + max-height: 100%;
25 27 font-size: 18px !important;
26 28 background-color: #008000;
27 29 }
28 30
29 31 md-toast.tb-error-toast .md-toast-content {
30 32 height: 100%;
  33 + max-height: 100%;
31 34 font-size: 18px !important;
32 35 background-color: #800000;
33 36 }
... ...