Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
QuiteAFancyEmerald
GitHub Repository: QuiteAFancyEmerald/Holy-Unblocker
Path: blob/master/lib/rammerhead/src/util/addMoreErrorGuards.js
6530 views
1
// handle the additional errors: ERR_INVALID_PROTOCOL and ETIMEDOUT
2
// hammerhead handled errors: ECONNRESET, EPIPE (or ECONNABORTED for windows)
3
4
const hGuard = require('testcafe-hammerhead/lib/request-pipeline/connection-reset-guard');
5
const isConnectionResetError = hGuard.isConnectionResetError;
6
hGuard.isConnectionResetError = function (err) {
7
// for some reason, ECONNRESET isn't handled correctly
8
if (
9
isConnectionResetError(err) ||
10
err.code === 'ERR_INVALID_PROTOCOL' ||
11
err.code === 'ETIMEDOUT' ||
12
err.code === 'ECONNRESET' ||
13
err.code === 'EPIPE'
14
) {
15
return true;
16
}
17
console.error('Unknown crash-inducing error:', err);
18
// never return false as to avoid crashing the server
19
return true;
20
};
21
22
process.on('uncaughtException', (err) => {
23
// for some reason, the above never catches all of the errors. this is a last resort failsafe
24
if (
25
err.message.includes('ECONN') ||
26
err.message.includes('EPIPE') ||
27
err.message.includes('ETIMEDOUT') ||
28
err.message.includes('ERR_INVALID_')
29
) {
30
// crash avoided!
31
console.error('Avoided crash:' + err.message);
32
} else {
33
// probably a TypeError or something important
34
console.error('Something broke...', err)
35
}
36
});
37
38