Skip to content

Commit bcf9535

Browse files
authored
Update download-database to read our error messages
1 parent 495ec76 commit bcf9535

3 files changed

Lines changed: 22 additions & 20 deletions

File tree

lib/download-database.js

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/download-database.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/download-database.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ import { IHeaders } from "@actions/http-client/interfaces";
1212
import * as io from "@actions/io";
1313

1414
export 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
}
2024
const 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

Comments
 (0)