-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: more lax timeout and socket error detection
- Loading branch information
Showing
2 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters