diff --git a/helpers/is-socket-error.js b/helpers/is-socket-error.js index 99f7b7c1b3..d94e503e3c 100644 --- a/helpers/is-socket-error.js +++ b/helpers/is-socket-error.js @@ -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; diff --git a/helpers/is-timeout-error.js b/helpers/is-timeout-error.js index cc3ca10a49..6b8ffea8b3 100644 --- a/helpers/is-timeout-error.js +++ b/helpers/is-timeout-error.js @@ -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; }