-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: consider more unreachable website codes
- Loading branch information
Showing
2 changed files
with
34 additions
and
11 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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// When it's an error related to the remote server or the connection we skip it since we have no control over it | ||
export function handleReachabilityError(error: Error) { | ||
if ( | ||
![ | ||
// The server is unreachable, since the route may be broken temporarily we skip the domain to be reprocessed next time | ||
'ECONNREFUSED', | ||
'ECONNRESET', | ||
'ENETUNREACH', | ||
'ENOTFOUND', | ||
'UND_ERR_SOCKET', | ||
'UND_ERR_CONNECT_TIMEOUT', | ||
// Some websites return wrongly formatted headers (like https://mesads.beta.gouv.fr/robots.txt due to the provider Clever Cloud) | ||
// Which makes `fetch()` failing with `HPE_INVALID_HEADER_TOKEN ... Invalid header value char`. | ||
'HPE_INVALID_HEADER_TOKEN', | ||
// Hostname/IP does not match certificate's altnames (which makes the certificate invalid) | ||
'ERR_TLS_CERT_ALTNAME_INVALID', | ||
'DEPTH_ZERO_SELF_SIGNED_CERT', | ||
].includes((error.cause as any)?.code || '') | ||
) { | ||
throw error; | ||
} | ||
} |