Skip to content

Commit cf87cbb

Browse files
committed
chore(WebSocketShard): move zlib-sync error numbers to constants file
1 parent a61a832 commit cf87cbb

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

packages/ws/src/utils/constants.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import process from 'node:process';
22
import { Collection } from '@discordjs/collection';
33
import { lazy } from '@discordjs/util';
44
import { APIVersion, GatewayOpcodes } from 'discord-api-types/v10';
5+
import * as ZlibSync from 'zlib-sync';
56
import { SimpleShardingStrategy } from '../strategies/sharding/SimpleShardingStrategy.js';
67
import { SimpleIdentifyThrottler } from '../throttling/SimpleIdentifyThrottler.js';
78
import type { SessionInfo, OptionalWebSocketManagerOptions, WebSocketManager } from '../ws/WebSocketManager.js';
@@ -31,6 +32,17 @@ export const CompressionParameterMap = {
3132
[CompressionMethod.ZlibSync]: 'zlib-stream',
3233
} as const satisfies Record<CompressionMethod, string>;
3334

35+
export const ZlibErrorCodes = {
36+
[ZlibSync.Z_NEED_DICT]: 'Z_NEED_DICT',
37+
[ZlibSync.Z_STREAM_END]: 'Z_STREAM_END',
38+
[ZlibSync.Z_ERRNO]: 'Z_ERRNO',
39+
[ZlibSync.Z_STREAM_ERROR]: 'Z_STREAM_ERROR',
40+
[ZlibSync.Z_DATA_ERROR]: 'Z_DATA_ERROR',
41+
[ZlibSync.Z_MEM_ERROR]: 'Z_MEM_ERROR',
42+
[ZlibSync.Z_BUF_ERROR]: 'Z_BUF_ERROR',
43+
[ZlibSync.Z_VERSION_ERROR]: 'Z_VERSION_ERROR',
44+
} as const satisfies Record<number, string>;
45+
3446
/**
3547
* Default options used by the manager
3648
*/

packages/ws/src/ws/WebSocketShard.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { IContextFetchingStrategy } from '../strategies/context/IContextFet
2525
import {
2626
CompressionMethod,
2727
CompressionParameterMap,
28+
ZlibErrorCodes,
2829
ImportantGatewayOpcodes,
2930
getInitialSendRateLimitState,
3031
} from '../utils/constants.js';
@@ -59,17 +60,6 @@ export enum WebSocketShardDestroyRecovery {
5960
Resume,
6061
}
6162

62-
enum ZlibErrorCodes {
63-
Z_NEED_DICT = 2,
64-
Z_STREAM_END = 1,
65-
Z_ERRNO = -1,
66-
Z_STREAM_ERROR = -2,
67-
Z_DATA_ERROR = -3,
68-
Z_MEM_ERROR = -4,
69-
Z_BUF_ERROR = -5,
70-
Z_VERSION_ERROR = -6,
71-
}
72-
7363
export interface WebSocketShardEventsMap {
7464
[WebSocketShardEvents.Closed]: [code: number];
7565
[WebSocketShardEvents.Debug]: [message: string];

0 commit comments

Comments
 (0)