File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,17 @@ export enum WebSocketShardDestroyRecovery {
59
59
Resume ,
60
60
}
61
61
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
+
62
73
export interface WebSocketShardEventsMap {
63
74
[ WebSocketShardEvents . Closed ] : [ code : number ] ;
64
75
[ WebSocketShardEvents . Debug ] : [ message : string ] ;
@@ -667,10 +678,11 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
667
678
this . zLibSyncInflate . push ( Buffer . from ( decompressable ) , flush ? zLibSync . Z_SYNC_FLUSH : zLibSync . Z_NO_FLUSH ) ;
668
679
669
680
if ( this . zLibSyncInflate . err ) {
670
- this . emit (
671
- WebSocketShardEvents . Error ,
672
- new Error ( `${ this . zLibSyncInflate . err } ${ this . zLibSyncInflate . msg ? `: ${ this . zLibSyncInflate . msg } ` : '' } ` ) ,
673
- ) ;
681
+ // Try to match nodejs zlib errors as much as possible
682
+ const error : NodeJS . ErrnoException = new Error ( this . zLibSyncInflate . msg ?? undefined ) ;
683
+ error . errno = this . zLibSyncInflate . err ;
684
+ error . code = ZlibErrorCodes [ this . zLibSyncInflate . err ] ;
685
+ this . emit ( WebSocketShardEvents . Error , error ) ;
674
686
}
675
687
676
688
if ( ! flush ) {
You can’t perform that action at this time.
0 commit comments