throw error on invalid response while downloading attachment

This commit is contained in:
Audric Ackermann 2020-10-27 12:37:26 +11:00
parent 7c47150194
commit 68e9376c5e
No known key found for this signature in database
GPG key ID: 999F434D76324AD4

View file

@ -26,10 +26,16 @@ export async function downloadAttachment(attachment: any) {
}
// Fallback to using the default fileserver
if (defaultFileserver || !res) {
if (defaultFileserver || !res || !res.ok) {
res = await window.lokiFileServerAPI.downloadAttachment(attachment.url);
}
if (!res.response || !res.response.data) {
throw new Error(
`downloadAttachment: invalid response for ${attachment.url}`
);
}
// The attachment id is actually just the absolute url of the attachment
let data = new Uint8Array(res.response.data).buffer;
if (!attachment.isRaw) {