From 9094ade2c01c97fb9b5e49ffbdbe0fae2adb8975 Mon Sep 17 00:00:00 2001 From: Tiffany <11891012+t1ff4ny@users.noreply.github.com> Date: Mon, 11 Sep 2023 04:07:46 +1000 Subject: [PATCH] Handle error thrown in postConfigUpdateToAPI (#3299) Co-authored-by: Tiffany L --- web/utils/config-constants.tsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/web/utils/config-constants.tsx b/web/utils/config-constants.tsx index c5f7a549c..d9e89cf85 100644 --- a/web/utils/config-constants.tsx +++ b/web/utils/config-constants.tsx @@ -54,15 +54,22 @@ const TEXTFIELD_TYPE_URL = 'url'; export async function postConfigUpdateToAPI(args: ApiPostArgs) { const { apiPath, data, onSuccess, onError } = args; - const result = await fetchData(`${SERVER_CONFIG_UPDATE_URL}${apiPath}`, { - data, - method: 'POST', - auth: true, - }); - if (result.success && onSuccess) { - onSuccess(result.message); - } else if (onError) { - onError(result.message); + try { + const result = await fetchData(`${SERVER_CONFIG_UPDATE_URL}${apiPath}`, { + data, + method: 'POST', + auth: true, + }); + if (result.success && onSuccess) { + onSuccess(result.message); + } else if (onError) { + onError(result.message); + } + } + catch (e) { + if (onError) { + onError(e.message); + } } }