Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Return after handling an error when getting a file (#60)
Browse files Browse the repository at this point in the history
Fixes #55

It looks like the code assumes `reject` returns after handling an error, which doesn't seem to be the case in javascript.
Also improve the error handling a bit so the client doesn't get `Unhandled server error`.

Introduced in #47
  • Loading branch information
babolivier authored Dec 8, 2021
1 parent d07a2a7 commit 84a26ee
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,20 @@ async function _generateReportFromDownload(req, domain, mediaId, matrixFile, opt

// Download the media
get(opts, (err, res) => {
if (err) reject(err);
if (err) {
reject(err);
return;
}

// Write the file
res.pipe(fileWriteStream);

// Save the response headers
resolve(res.headers);
});
}).catch(err => {
console.error(`Failed to download file: ${err.message}`);
throw new ClientError(502, 'Failed to get requested URL', 'MCS_MEDIA_REQUEST_FAILED');
});
} catch (err) {
if (!err.statusCode) {
Expand Down

0 comments on commit 84a26ee

Please sign in to comment.