Skip to content

Commit 8714987

Browse files
committed
Try deferring errors to help with possible unterminated JSON error case
1 parent 980aa2a commit 8714987

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/api/rest-api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,13 @@ function handleErrors<
191191
logError(error);
192192

193193
// Use default error handler if response started (kills the connection)
194-
if (res.headersSent) return next(error)
195-
else {
194+
if (res.headersSent) {
195+
// We defer because there seems to be some kind of partial response issue in some edge cases,
196+
// and calling next() early while a resopnse is pending would trigger exactly that.
197+
return setImmediate(() =>
198+
next(error)
199+
);
200+
} else {
196201
const status = (error.statusCode && error.statusCode >= 400 && error.statusCode < 600)
197202
? error.statusCode
198203
: 500;

0 commit comments

Comments
 (0)