1
+ import { STATUS_CODES } from 'node:http' ;
1
2
import { createInterface } from 'node:readline' ;
2
3
import fetch from 'node-fetch' ;
3
4
import { KubeConfig } from './config.js' ;
@@ -54,11 +55,14 @@ export class Watch {
54
55
const response = await fetch ( watchURL , requestInit ) ;
55
56
56
57
if ( response . status === 200 ) {
57
- response . body . on ( 'error' , doneCallOnce ) ;
58
- response . body . on ( 'close' , ( ) => doneCallOnce ( null ) ) ;
59
- response . body . on ( 'finish' , ( ) => doneCallOnce ( null ) ) ;
58
+ const body = response . body ! ;
60
59
61
- const lines = createInterface ( response . body ) ;
60
+ body . on ( 'error' , doneCallOnce ) ;
61
+ body . on ( 'close' , ( ) => doneCallOnce ( null ) ) ;
62
+ body . on ( 'end' , ( ) => doneCallOnce ( null ) ) ;
63
+ body . on ( 'finish' , ( ) => doneCallOnce ( null ) ) ;
64
+
65
+ const lines = createInterface ( body ) ;
62
66
lines . on ( 'error' , doneCallOnce ) ;
63
67
lines . on ( 'close' , ( ) => doneCallOnce ( null ) ) ;
64
68
lines . on ( 'finish' , ( ) => doneCallOnce ( null ) ) ;
@@ -71,7 +75,9 @@ export class Watch {
71
75
}
72
76
} ) ;
73
77
} else {
74
- const error = new Error ( response . statusText ) as Error & {
78
+ const statusText =
79
+ response . statusText || STATUS_CODES [ response . status ] || 'Internal Server Error' ;
80
+ const error = new Error ( statusText ) as Error & {
75
81
statusCode : number | undefined ;
76
82
} ;
77
83
error . statusCode = response . status ;
0 commit comments