Path: blob/master/lib/rammerhead/src/util/addMoreErrorGuards.js
6530 views
// handle the additional errors: ERR_INVALID_PROTOCOL and ETIMEDOUT1// hammerhead handled errors: ECONNRESET, EPIPE (or ECONNABORTED for windows)23const hGuard = require('testcafe-hammerhead/lib/request-pipeline/connection-reset-guard');4const isConnectionResetError = hGuard.isConnectionResetError;5hGuard.isConnectionResetError = function (err) {6// for some reason, ECONNRESET isn't handled correctly7if (8isConnectionResetError(err) ||9err.code === 'ERR_INVALID_PROTOCOL' ||10err.code === 'ETIMEDOUT' ||11err.code === 'ECONNRESET' ||12err.code === 'EPIPE'13) {14return true;15}16console.error('Unknown crash-inducing error:', err);17// never return false as to avoid crashing the server18return true;19};2021process.on('uncaughtException', (err) => {22// for some reason, the above never catches all of the errors. this is a last resort failsafe23if (24err.message.includes('ECONN') ||25err.message.includes('EPIPE') ||26err.message.includes('ETIMEDOUT') ||27err.message.includes('ERR_INVALID_')28) {29// crash avoided!30console.error('Avoided crash:' + err.message);31} else {32// probably a TypeError or something important33console.error('Something broke...', err)34}35});363738