Skip to content

Commit

Permalink
fix(GotDownloader): add URL to 404 error message (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Feb 10, 2020
1 parent 2422ca4 commit 16c4ec2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/GotDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class GotDownloader implements Downloader<any> {
downloadStream.pipe(writeStream);

downloadStream.on('error', error => {
if (error.name === 'HTTPError' && error.statusCode === 404) {
error.message += ` for ${error.url}`;
}
if (writeStream.destroy) {
writeStream.destroy(error);
}
Expand Down
10 changes: 4 additions & 6 deletions test/GotDownloader.network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ describe('GotDownloader', () => {
const downloader = new GotDownloader();
await withTempDirectory(async dir => {
const testFile = path.resolve(dir, 'test.txt');
await expect(
downloader.download(
'https://github.com/electron/electron/releases/download/v2.0.18/bad.file',
testFile,
),
).rejects.toMatchInlineSnapshot(`[HTTPError: Response code 404 (Not Found)]`);
const url = 'https://github.com/electron/electron/releases/download/v2.0.18/bad.file';
await expect(downloader.download(url, testFile)).rejects.toMatchInlineSnapshot(
`[HTTPError: Response code 404 (Not Found) for ${url}]`,
);
});
});

Expand Down

0 comments on commit 16c4ec2

Please sign in to comment.