Skip to content

Commit 9e9435b

Browse files
committed
fix: enhance error handling in downloadFile function with detailed response information
1 parent 5c12189 commit 9e9435b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/helpers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@ export async function downloadFile(
3434
): Promise<DownloadResponse> {
3535
const response = await fetch(url);
3636
if (!response.ok) {
37-
throw new Error("Response error.");
37+
let responseText = "";
38+
try {
39+
responseText = await response.text();
40+
} catch {
41+
responseText = "";
42+
}
43+
const details = [
44+
`status=${response.status}`,
45+
`statusText=${response.statusText || "unknown"}`,
46+
];
47+
if (responseText) {
48+
details.push(`body=${responseText.slice(0, 500)}`);
49+
}
50+
details.push(`url=${url}`);
51+
throw new Error(`Response error. ${details.join(" ")}`);
3852
}
3953

4054
const defaultName = !isNaN(index) && index > -1 ? `file_${index}.out` : 'file.out'

0 commit comments

Comments
 (0)