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,7 +263,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
263 if (regularUserSessions.size() < maxSessionsPerRegularUser) { 263 if (regularUserSessions.size() < maxSessionsPerRegularUser) {
264 regularUserSessions.add(sessionId); 264 regularUserSessions.add(sessionId);
265 } else { 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 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId); 267 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId);
268 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max regular user sessions limit reached")); 268 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max regular user sessions limit reached"));
269 return false; 269 return false;
@@ -276,7 +276,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr @@ -276,7 +276,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr
276 if (publicUserSessions.size() < maxSessionsPerPublicUser) { 276 if (publicUserSessions.size() < maxSessionsPerPublicUser) {
277 publicUserSessions.add(sessionId); 277 publicUserSessions.add(sessionId);
278 } else { 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 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId); 280 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), sessionId);
281 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max public user sessions limit reached")); 281 session.close(CloseStatus.POLICY_VIOLATION.withReason("Max public user sessions limit reached"));
282 return false; 282 return false;
@@ -266,7 +266,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi @@ -266,7 +266,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
266 } else if (customerSessions.size() < maxSubscriptionsPerCustomer) { 266 } else if (customerSessions.size() < maxSubscriptionsPerCustomer) {
267 customerSessions.add(subId); 267 customerSessions.add(subId);
268 } else { 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 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId); 270 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
271 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max customer subscriptions limit reached")); 271 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max customer subscriptions limit reached"));
272 return false; 272 return false;
@@ -279,7 +279,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi @@ -279,7 +279,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
279 if (regularUserSessions.size() < maxSubscriptionsPerRegularUser) { 279 if (regularUserSessions.size() < maxSubscriptionsPerRegularUser) {
280 regularUserSessions.add(subId); 280 regularUserSessions.add(subId);
281 } else { 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 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId); 283 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
284 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max regular user subscriptions limit reached")); 284 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max regular user subscriptions limit reached"));
285 return false; 285 return false;
@@ -292,7 +292,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi @@ -292,7 +292,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
292 if (publicUserSessions.size() < maxSubscriptionsPerPublicUser) { 292 if (publicUserSessions.size() < maxSubscriptionsPerPublicUser) {
293 publicUserSessions.add(subId); 293 publicUserSessions.add(subId);
294 } else { 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 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId); 296 , sessionRef.getSecurityCtx().getTenantId(), sessionRef.getSecurityCtx().getId(), subId);
297 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max public user subscriptions limit reached")); 297 msgEndpoint.close(sessionRef, CloseStatus.POLICY_VIOLATION.withReason("Max public user subscriptions limit reached"));
298 return false; 298 return false;
@@ -26,7 +26,7 @@ const WS_IDLE_TIMEOUT = 90000; @@ -26,7 +26,7 @@ const WS_IDLE_TIMEOUT = 90000;
26 const MAX_PUBLISH_COMMANDS = 10; 26 const MAX_PUBLISH_COMMANDS = 10;
27 27
28 /*@ngInject*/ 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 var isOpening = false, 31 var isOpening = false,
32 isOpened = false, 32 isOpened = false,
@@ -111,7 +111,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to @@ -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 isOpening = false; 118 isOpening = false;
116 } 119 }
117 120
@@ -137,7 +140,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to @@ -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 isOpening = false; 147 isOpening = false;
142 isOpened = false; 148 isOpened = false;
143 if (isActive) { 149 if (isActive) {
@@ -191,7 +197,9 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to @@ -191,7 +197,9 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, to
191 } else { 197 } else {
192 message += "error code - " + errorCode + "."; 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 function fetchKeys(subscriptionId) { 205 function fetchKeys(subscriptionId) {
@@ -16,18 +16,21 @@ @@ -16,18 +16,21 @@
16 16
17 md-toast.tb-info-toast .md-toast-content { 17 md-toast.tb-info-toast .md-toast-content {
18 height: 100%; 18 height: 100%;
  19 + max-height: 100%;
19 padding: 18px; 20 padding: 18px;
20 font-size: 18px; 21 font-size: 18px;
21 } 22 }
22 23
23 md-toast.tb-success-toast .md-toast-content { 24 md-toast.tb-success-toast .md-toast-content {
24 height: 100%; 25 height: 100%;
  26 + max-height: 100%;
25 font-size: 18px !important; 27 font-size: 18px !important;
26 background-color: #008000; 28 background-color: #008000;
27 } 29 }
28 30
29 md-toast.tb-error-toast .md-toast-content { 31 md-toast.tb-error-toast .md-toast-content {
30 height: 100%; 32 height: 100%;
  33 + max-height: 100%;
31 font-size: 18px !important; 34 font-size: 18px !important;
32 background-color: #800000; 35 background-color: #800000;
33 } 36 }