@@ -324,7 +324,7 @@ function asPromise(opts) {
324324 }
325325
326326 if ( statusCode !== 304 && ( statusCode < 200 || statusCode > limitStatusCode ) ) {
327- throw new got . HTTPError ( statusCode , res . headers , opts ) ;
327+ throw new got . HTTPError ( statusCode , res . statusMessage , res . headers , opts ) ;
328328 }
329329
330330 resolve ( res ) ;
@@ -407,7 +407,7 @@ function asStream(opts) {
407407 res . pipe ( output ) ;
408408
409409 if ( statusCode !== 304 && ( statusCode < 200 || statusCode > 299 ) ) {
410- proxy . emit ( 'error' , new got . HTTPError ( statusCode , res . headers , opts ) , null , res ) ;
410+ proxy . emit ( 'error' , new got . HTTPError ( statusCode , res . statusMessage , res . headers , opts ) , null , res ) ;
411411 return ;
412412 }
413413
@@ -627,8 +627,12 @@ got.ParseError = class extends StdError {
627627} ;
628628
629629got . HTTPError = class extends StdError {
630- constructor ( statusCode , headers , opts ) {
631- const statusMessage = http . STATUS_CODES [ statusCode ] ;
630+ constructor ( statusCode , statusMessage , headers , opts ) {
631+ if ( statusMessage ) {
632+ statusMessage = statusMessage . replace ( / \r ? \n / g, ' ' ) . trim ( ) ;
633+ } else {
634+ statusMessage = http . STATUS_CODES [ statusCode ] ;
635+ }
632636 super ( `Response code ${ statusCode } (${ statusMessage } )` , { } , opts ) ;
633637 this . name = 'HTTPError' ;
634638 this . statusCode = statusCode ;
0 commit comments