Thumbnail uploads: handle non-JSON responses

This commit is contained in:
infinite-persistence 2022-01-06 11:49:19 +08:00
parent 01459d906a
commit 57f48f462e
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -441,7 +441,13 @@ export const doUploadThumbnail = (
body: data, body: data,
}) })
.then((res) => res.text()) .then((res) => res.text())
.then((text) => (text.length ? JSON.parse(text) : {})) .then((text) => {
try {
return text.length ? JSON.parse(text) : {};
} catch {
throw new Error(text);
}
})
.then((json) => { .then((json) => {
if (json.type !== 'success') { if (json.type !== 'success') {
return uploadError( return uploadError(
@ -470,7 +476,7 @@ export const doUploadThumbnail = (
} }
const userInput = [fileName, fileExt, fileType, thumbnail]; const userInput = [fileName, fileExt, fileType, thumbnail];
uploadError(`${message}\nUser input: ${userInput.join(', ')}`); uploadError(`${message}\nUser input: ${userInput.join(' | ')}`);
}); });
}; };