@@ -16,6 +16,14 @@ function handlerWrapper(handler, handle, ...args) {
16
16
}
17
17
}
18
18
19
+ function handlerStreamWrapper ( handler , handle , ...args ) {
20
+ try {
21
+ handler . call ( this , ...args )
22
+ } catch ( error ) {
23
+ logger . error ( 'caught error from stream api handler' , handle , error . message , 'continuing' , error )
24
+ }
25
+ }
26
+
19
27
class API {
20
28
constructor ( ) {
21
29
this . users = [ ]
@@ -65,6 +73,7 @@ class API {
65
73
. on ( 'connect_timeout' , error => {
66
74
logger . error ( 'socket io connection_timeout' , error , this )
67
75
} )
76
+ . on ( 'error' , err => logger . error ( 'socketAPI server caught error' , err ) )
68
77
} catch ( error ) {
69
78
logger . error ( 'API start caught error' , error )
70
79
}
@@ -144,17 +153,19 @@ class API {
144
153
socket . emit ( 'OK ' + event , ...responses )
145
154
}
146
155
147
- socket . error = error => {
148
- logger . error ( 'api connected socket.error caught error' , error )
149
- }
150
156
var ssSocket
151
157
152
158
for ( let handle in this . handlers ) {
153
159
if ( handle . endsWith ( 'development' ) && process . env . NODE_ENV !== 'development' ) continue // ignore handlers that end with "development" in production
154
160
if ( handle . startsWith ( 'stream' ) ) {
155
- if ( ! ssSocket ) ssSocket = ss ( socket )
161
+ if ( ! ssSocket ) {
162
+ ssSocket = ss ( socket )
163
+ ssSocket . on ( 'error' , err => logger . error ( 'socket-api ssSocket error' , err ) )
164
+ ssSocket . on ( 'uncaughtException' , err => logger . error ( 'socket uncaught' , err ) )
165
+ ssSocket . on ( 'close' , ( ) => console . error ( 'got close' ) )
166
+ }
156
167
// handlers that use streams need to start with 'stream' and they are wrapped differently to work
157
- ssSocket . on ( handle , handlerWrapper . bind ( ssSocket , this . handlers [ handle ] , handle ) )
168
+ ssSocket . on ( handle , handlerStreamWrapper . bind ( ssSocket , this . handlers [ handle ] , handle ) )
158
169
} else socket . on ( handle , handlerWrapper . bind ( socket , this . handlers [ handle ] , handle ) )
159
170
}
160
171
// thanks to https://stackoverflow.com/questions/41751141/socket-io-how-to-access-unhandled-messages
0 commit comments