@applitools/execution-grid-tunnel
Version:
Allows user to run tests with exection-grid and navigate to private hosts and ips
51 lines (47 loc) • 1.97 kB
JavaScript
/**
* Typed startup error for PAC load / compile failures.
*
* Shape mirrors `FrpcDownloadError` so SDK consumers can branch on the
* same conventions (`userError === true`, custom `code`, contextual
* fields). Runtime PAC errors per request are NOT thrown — they are
* logged via the existing structured logger and the request falls
* through to DIRECT (see `init-socks5-proxy-server.js`).
*
* Codes:
* - EG_TUNNEL_PAC_FILE_LOAD_FAILED — `pacFile` path missing / unreadable
* - EG_TUNNEL_PAC_URL_LOAD_FAILED — `pacUrl` fetch failed (network / 4xx / 5xx / 10s timeout)
* - EG_TUNNEL_PAC_COMPILE_FAILED — PAC source is invalid JavaScript or lacks `FindProxyForURL`
*
* Each instance carries: `code`, `name='PacError'`, `userError=true`,
* `sourceKind: 'file'|'script'|'url'`, `source` (path / url / '<inline>'),
* `cause` (the underlying error).
*/
class PacError extends Error {
constructor({code, message, sourceKind, source, cause}) {
super(message || defaultMessage(code, sourceKind, source, cause))
if (Error.captureStackTrace) {
Error.captureStackTrace(this, PacError)
}
this.name = 'PacError'
this.userError = true
this.code = code
this.sourceKind = sourceKind
this.source = source
this.cause = cause
}
}
function defaultMessage(code, sourceKind, source, cause) {
const causeMsg = cause && (cause.message || String(cause))
switch (code) {
case 'EG_TUNNEL_PAC_FILE_LOAD_FAILED':
return `Failed to read PAC file at "${source}"${causeMsg ? `: ${causeMsg}` : ''}`
case 'EG_TUNNEL_PAC_URL_LOAD_FAILED':
return `Failed to fetch PAC URL "${source}"${causeMsg ? `: ${causeMsg}` : ''}`
case 'EG_TUNNEL_PAC_COMPILE_FAILED':
return `Failed to compile PAC source (${sourceKind} "${source}")${causeMsg ? `: ${causeMsg}` : ''}`
default:
return `PAC error (${code})${causeMsg ? `: ${causeMsg}` : ''}`
}
}
module.exports = {PacError}