Skip to content

Commit c9c8bdb

Browse files
author
Ivaylo Andonov
committed
feat(util): expose isConnectionError check
1 parent a1d5015 commit c9c8bdb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/util/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './BigIntMath';
33
export * from './isNotNil';
44
export * from './replaceNullsToUndefineds';
55
export * from './serializableObject';
6+
export * from './network';

packages/util/src/network.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
3+
export const connectionErrorCodes = ['ENOTFOUND', 'ECONNREFUSED', 'ECONNRESET'];
4+
5+
export const isConnectionError = (error: any) => {
6+
if (
7+
(error?.code && connectionErrorCodes.includes(error.code)) ||
8+
(error?.message && connectionErrorCodes.some((err) => error.message.includes(err)))
9+
) {
10+
return true;
11+
}
12+
return false;
13+
};

0 commit comments

Comments
 (0)