-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathQuery.js
More file actions
25 lines (21 loc) · 733 Bytes
/
Query.js
File metadata and controls
25 lines (21 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Error codes where the request definitely never reached the server
const noConnectionErrorCodes = new Set([
"ECONNREFUSED",
"ENETUNREACH",
]);
// Error codes where the connection may have been established
// before failing, so the server may have received the request
const ambiguousConnectionErrorCodes = new Set([
"ETIMEDOUT",
"ECONNRESET",
]);
const getCode = (error) => {
const code = error?.cause?.code;
return typeof code === "string" ? code : "";
};
export const isNoConnectionError = (error) =>
noConnectionErrorCodes.has(getCode(error));
export const isConnectionError = (error) => {
const code = getCode(error);
return noConnectionErrorCodes.has(code) || ambiguousConnectionErrorCodes.has(code);
};