Skip to content

Commit 87d5951

Browse files
authored
Merge pull request #29 from bnoguchi/fix/500-json-parse
fix: uploadFile throws `Uncaught SyntaxError: Unexpected end of JSON input` when 500 response
2 parents 42727a9 + 134d56f commit 87d5951

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/utils/request.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export const uploadFile = (formData, callback) => {
8282
}
8383
else if (uploadFileXHR.status !== 200) {
8484
if (typeof callback != "function") return;
85-
callback(JSON.parse(uploadFileXHR.responseText));
85+
try {
86+
callback(JSON.parse(uploadFileXHR.responseText));
87+
} catch (ex) {
88+
callback(ex);
89+
}
8690
}
8791
};
8892
uploadFileXHR.send(formData);

0 commit comments

Comments
 (0)