File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,15 @@ import * as path from 'node:path'
8
8
import * as url from 'node:url'
9
9
import sourceMapSupport from 'source-map-support'
10
10
11
+ // To make sure everything keeps working and the server doesn't crash, if
12
+ // there are any uncaught errors, log them out gracefully
13
+ process . on ( 'uncaughtException' , ( err ) => {
14
+ console . error ( 'server uncaught exception' , err )
15
+ } )
16
+ process . on ( 'unhandledRejection' , ( err ) => {
17
+ console . error ( 'server unhandled rejection' , err )
18
+ } )
19
+
11
20
// figlet -f isometric3 'utopia'
12
21
const asciiBanner = `
13
22
___ ___ ___ ___
@@ -143,7 +152,14 @@ function proxy(originalRequest, originalResponse) {
143
152
} ,
144
153
)
145
154
146
- originalRequest . pipe ( proxyRequest )
155
+ originalRequest
156
+ . pipe ( proxyRequest )
157
+ // if the request fails for any non-explicit reason (e.g. ERRCONNREFUSED),
158
+ // handle the error gracefully and return a common status code back to the client
159
+ . on ( 'error' , ( err ) => {
160
+ console . error ( 'failed proxy request' , err )
161
+ originalResponse . status ( 502 ) . json ( { error : 'Service temporarily unavailable' } )
162
+ } )
147
163
}
148
164
149
165
const corsMiddleware = cors ( {
You can’t perform that action at this time.
0 commit comments