Skip to content

Commit

Permalink
Improve non-200 error
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Jan 4, 2024
1 parent b1c3903 commit 3e97dd6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function fetch(urlObj: UrlWithStringQuery, pathStr: string) {
break;
default:
throw new Error(
`fetch(): Unrecognised protocol in provided url: ${url.format(urlObj)}`
`fetch(): Unrecognised protocol in provided url: ${url.format(urlObj)}`,
);
}
return new Promise(function (resolve, reject) {
Expand All @@ -87,7 +87,9 @@ export function fetch(urlObj: UrlWithStringQuery, pathStr: string) {
resolve(pathStr);
});
} else {
reject(new Error("non 200 statusCode"));
reject(
new Error(`Non 200 statusCode for url: ${url.format(urlObj)}`),
);
}
})
.on("error", reject);
Expand Down Expand Up @@ -188,14 +190,14 @@ export async function download(urlStrWithChecksum: $path, pkgPath: $path) {
urlStr,
downloadPath,
checksumAlgo,
hashStr
hashStr,
) {
let tmpDownloadPath = downloadPath + ".tmp";
await fetch(url.parse(urlStr), tmpDownloadPath);
let checksum = await computeChecksum(tmpDownloadPath, checksumAlgo);
if (hashStr !== checksum) {
throw new Error(
`Downloaded by checksum failed. url: ${url} downloadPath: ${downloadPath} checksum expected: ${hashStr} checksum computed: ${checksum} checksum algorithm: ${checksumAlgo}`
`Downloaded by checksum failed. url: ${url} downloadPath: ${downloadPath} checksum expected: ${hashStr} checksum computed: ${checksum} checksum algorithm: ${checksumAlgo}`,
);
} else {
await fs.move(tmpDownloadPath, downloadPath);
Expand Down

0 comments on commit 3e97dd6

Please sign in to comment.