Skip to content

Commit

Permalink
Try deferring errors to help with possible unterminated JSON error case
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jan 13, 2025
1 parent 980aa2a commit 8714987
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/api/rest-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,13 @@ function handleErrors<
logError(error);

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

0 comments on commit 8714987

Please sign in to comment.