Added more details to the error message

This commit is contained in:
Kir_Antipov 2021-09-26 20:05:59 +03:00
parent 5bc986e4cc
commit e07b3d5c99
2 changed files with 10 additions and 2 deletions

View file

@ -97,7 +97,11 @@ export async function uploadFile(id: string, data: Record<string, any>, file: Fi
});
if (!response.ok) {
throw new Error(`Failed to upload file: ${response.status} (${response.statusText})`)
let errorText = response.statusText;
try {
errorText += `, ${await response.text()}`;
} catch { }
throw new Error(`Failed to upload file: ${response.status} (${errorText})`);
}
return (<{ id: number }>await response.json()).id;

View file

@ -23,7 +23,11 @@ export async function createVersion(id: string, data: Record<string, any>, files
});
if (!response.ok) {
throw new Error(`Failed to upload file: ${response.status} (${response.statusText})`)
let errorText = response.statusText;
try {
errorText += `, ${await response.text()}`;
} catch { }
throw new Error(`Failed to upload file: ${response.status} (${errorText})`);
}
return (<{ id: string }>await response.json()).id;