From 1bc92ba92169603b6ad0d07bf62ec39433f7a0b5 Mon Sep 17 00:00:00 2001 From: Fannie MC <73371677+FannieMC@users.noreply.github.com> Date: Fri, 31 May 2024 12:15:09 +0800 Subject: [PATCH] Add JSON Parse Error Handling in Upload Script (#1196) * Add JSON Parse Error Handling in Upload Script * Update tinyfilemanager.php * Update tinyfilemanager.php --- tinyfilemanager.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index 7a085b21..e8405269 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -1422,10 +1422,14 @@ function getUploadExt() { toast('Error: Server Timeout'); }); }).on("success", function (res) { - let _response = JSON.parse(res.xhr.response); + try { + let _response = JSON.parse(res.xhr.response); - if(_response.status == "error") { - toast(_response.info); + if(_response.status == "error") { + toast(_response.info); + } + } catch (e) { + toast("Error: Invalid JSON response"); } }).on("error", function(file, response) { toast(response);