Skip to content

Commit

Permalink
fix: Handle JSON parsing error in uploadFile.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
shauryag2002 committed Dec 14, 2024
1 parent 130a6d6 commit 763f416
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Utils/request/uploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ const uploadFile = async (
xhr.onload = () => {
onLoad(xhr);
if (400 <= xhr.status && xhr.status <= 499) {
const error = JSON.parse(xhr.responseText);
let error;
try {
error = JSON.parse(xhr.responseText);
} catch {
error = xhr.responseText;
}
if (typeof error === "object" && !Array.isArray(error)) {
Object.values(error).forEach((msg) => {
Notification.Error({ msg: msg || "Something went wrong!" });
Expand Down

0 comments on commit 763f416

Please sign in to comment.