harden code
Massimo Melina committed
Apr 1, 2026 at 17:56 UTC
36af9b5e16368535d32f0ff40902141bd56286e2
1 file changed
+3
-3
src/index.ts
+3
-3
@@ -58,13 +58,13 @@ app.use(sessionMiddleware)
58
.on('error', errorHandler)
59
events.emit('app', app)
60
61
-function errorHandler(err:Error & { code:string, path:string }) {
61
+function errorHandler(err: Error & { code?: string, path?: string }) {
62
const { code } = err
63
- if (DEV && code === 'ENOENT' && err.path.endsWith('sockjs-node')) return // spam out dev stuff
63
+ if (DEV && code === 'ENOENT' && err.path?.endsWith('sockjs-node')) return // spam out dev stuff
64
if (code === 'ECANCELED' || code === 'ECONNRESET' || code === 'ECONNABORTED' || code === 'EPIPE'
65
|| code === 'ERR_STREAM_WRITE_AFTER_END' // happens disconnecting uploads, don't care
66
|| code === 'ERR_STREAM_PREMATURE_CLOSE' // happens when many files are sent (not locally), but I checked that the files are written completely. Introduced after node18.5.0 and is thrown by pipeline() used by PUT method handler.
67
- || code.startsWith('HPE')) return // malformed client/probe HTTP parser errors, not internal failures
67
+ || code?.startsWith('HPE')) return // malformed client/probe HTTP parser errors, not internal failures
68
console.error('server error', err)
69
}
70