@@ -12,9 +12,13 @@ import { IHeaders } from "@actions/http-client/interfaces";
1212import * as io from "@actions/io" ;
1313
1414export class HTTPError extends Error {
15- constructor ( readonly httpStatusCode : number | undefined ) {
16- super ( `Unexpected HTTP response: ${ httpStatusCode } ` ) ;
17- Object . setPrototypeOf ( this , new . target . prototype ) ;
15+ httpStatusCode : number | undefined ;
16+ httpMessage : string ;
17+ constructor ( httpStatusCode : number | undefined , httpMessage : string ) {
18+ super ( `Unexpected HTTP response: ${ httpStatusCode } . ${ httpMessage } ` ) ;
19+ // Set status code and error message to `this`
20+ this . httpStatusCode = httpStatusCode ;
21+ this . httpMessage = httpMessage ;
1822 }
1923}
2024const userAgent = "actions/tool-cache" ;
@@ -83,24 +87,24 @@ async function downloadDatabaseFileAttempt(
8387 headers . authorization = auth ;
8488 }
8589
86- core . debug ( JSON . stringify ( headers ) ) ;
87-
8890 const response : httpm . HttpClientResponse = await http . get ( url , headers ) ;
91+
8992 if ( response . message . statusCode !== 200 ) {
90- const err = new HTTPError ( response . message . statusCode ) ;
93+ const err = new HTTPError (
94+ response . message . statusCode ,
95+ await response . readBody ( )
96+ ) ;
9197 core . debug (
92- `Failed to download from "${ url } ". Code(${ response . message . statusCode } ) Message(${ response . message . statusMessage } )`
98+ `Failed to download from "${ url } ". Code(${ err . httpStatusCode } ) Message(${ err . httpMessage } )`
9399 ) ;
94100 throw err ;
95101 }
96102
97103 // Download the response body
98104 const pipeline = util . promisify ( stream . pipeline ) ;
99- const responseMessageFactory = ( ) => response . message ;
100- const readStream = responseMessageFactory ( ) ;
101105 let succeeded = false ;
102106 try {
103- await pipeline ( readStream , fs . createWriteStream ( dest ) ) ;
107+ await pipeline ( response . message , fs . createWriteStream ( dest ) ) ;
104108 core . debug ( "download complete" ) ;
105109 succeeded = true ;
106110 return dest ;
0 commit comments