1+ import { STATUS_CODES } from 'node:http' ;
12import { createInterface } from 'node:readline' ;
23import fetch from 'node-fetch' ;
34import { KubeConfig } from './config.js' ;
@@ -54,11 +55,13 @@ export class Watch {
5455 const response = await fetch ( watchURL , requestInit ) ;
5556
5657 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 ! ;
6059
61- const lines = createInterface ( response . body ) ;
60+ body . on ( 'error' , doneCallOnce ) ;
61+ body . on ( 'close' , ( ) => doneCallOnce ( null ) ) ;
62+ body . on ( 'finish' , ( ) => doneCallOnce ( null ) ) ;
63+
64+ const lines = createInterface ( body ) ;
6265 lines . on ( 'error' , doneCallOnce ) ;
6366 lines . on ( 'close' , ( ) => doneCallOnce ( null ) ) ;
6467 lines . on ( 'finish' , ( ) => doneCallOnce ( null ) ) ;
@@ -71,7 +74,9 @@ export class Watch {
7174 }
7275 } ) ;
7376 } else {
74- const error = new Error ( response . statusText ) as Error & {
77+ const statusText =
78+ response . statusText || STATUS_CODES [ response . status ] || 'Internal Server Error' ;
79+ const error = new Error ( statusText ) as Error & {
7580 statusCode : number | undefined ;
7681 } ;
7782 error . statusCode = response . status ;
0 commit comments