From 334ab504cf986b727db32e48519e0d0c76061abd Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 3 Apr 2022 09:53:02 +0200 Subject: [PATCH] process api resp --- packages/web/src/utility/api.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/web/src/utility/api.ts b/packages/web/src/utility/api.ts index cdcbb183..c4f6694b 100644 --- a/packages/web/src/utility/api.ts +++ b/packages/web/src/utility/api.ts @@ -22,8 +22,13 @@ function processApiResponse(route, args, resp) { } if (resp?.apiErrorMessage) { - showSnackbarError(resp?.apiErrorMessage); + showSnackbarError('API error:' + resp?.apiErrorMessage); + return { + errorMessage: resp.apiErrorMessage, + }; } + + return resp; } export async function apiCall(route: string, args: {} = undefined) { @@ -34,8 +39,7 @@ export async function apiCall(route: string, args: {} = undefined) { const electron = getElectron(); if (electron) { const resp = await electron.invoke(route.replace('/', '-'), args); - processApiResponse(route, args, resp); - return resp; + return processApiResponse(route, args, resp); } else { const resp = await fetch(`${resolveApi()}/${route}`, { method: 'POST', @@ -48,8 +52,7 @@ export async function apiCall(route: string, args: {} = undefined) { }); const json = await resp.json(); - processApiResponse(route, args, json); - return json; + return processApiResponse(route, args, json); } }