Skip to content

Commit

Permalink
fix: more lax timeout and socket error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Sep 27, 2023
1 parent 748b213 commit bb21af1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
26 changes: 16 additions & 10 deletions helpers/is-socket-error.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
function isSocketError(err) {
return Boolean(
err.message === 'Connection closed' ||
err.message === 'Connection pool was closed' ||
err.message === 'Connection closed unexpectedly' ||
err.message === 'Socket closed unexpectedly' ||
err.message === 'Unexpected socket close' ||
err.message === 'Timeout - closing connection' ||
err.message.includes('socket is already destroyed') ||
err.message.includes('socket is already half-closed')
);
if (typeof err !== 'object') return false;
for (const key of ['message', 'response']) {
if (typeof err[key] !== 'string') continue;
if (
err[key].includes('Connection closed') ||
err[key].includes('Connection pool was closed') ||
err[key].includes('Connection closed unexpectedly') ||
err[key].includes('Socket closed unexpectedly') ||
err[key].includes('Unexpected socket close') ||
err[key].includes('socket is already destroyed') ||
err[key].includes('socket is already half-closed')
)
return true;
}

return false;
}

module.exports = isSocketError;
18 changes: 12 additions & 6 deletions helpers/is-timeout-error.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
function isTimeoutError(err) {
if (typeof err !== 'object') return false;

if (err.name === 'TimeoutError' || err.name === 'AbortError') return true;

if (
err.message === 'Request aborted' ||
err.message === 'Timeout' ||
err.message === 'Request Time-out'
)
return true;
for (const key of ['message', 'response']) {
if (typeof err[key] !== 'string') continue;
if (
err[key].includes('Request aborted') ||
err[key].includes('Timeout') ||
err[key].includes('Request Time-out') ||
err[key].includes('Timeout - closing connection')
)
return true;
}

return false;
}
Expand Down

0 comments on commit bb21af1

Please sign in to comment.