From 763f4167f3d27dd2fb6b06cb194b3a55a8f55588 Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Sat, 14 Dec 2024 22:55:35 +0530 Subject: [PATCH] fix: Handle JSON parsing error in uploadFile.ts --- src/Utils/request/uploadFile.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Utils/request/uploadFile.ts b/src/Utils/request/uploadFile.ts index 3e0885fa7b8..ea603e1754f 100644 --- a/src/Utils/request/uploadFile.ts +++ b/src/Utils/request/uploadFile.ts @@ -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!" });