From 3b6e425e179e2c99bb041311544a79fa64b7830a Mon Sep 17 00:00:00 2001 From: Mary Hipp Date: Thu, 10 Aug 2023 13:38:52 -0400 Subject: [PATCH] fix error detail in toast --- .../web/src/features/system/store/systemSlice.ts | 11 +++++++++-- .../frontend/web/src/services/api/thunks/session.ts | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/src/features/system/store/systemSlice.ts b/invokeai/frontend/web/src/features/system/store/systemSlice.ts index fba980131e..079819fce7 100644 --- a/invokeai/frontend/web/src/features/system/store/systemSlice.ts +++ b/invokeai/frontend/web/src/features/system/store/systemSlice.ts @@ -365,12 +365,19 @@ export const systemSlice = createSlice({ state.statusTranslationKey = 'common.statusConnected'; state.progressImage = null; + let errorDescription = undefined; + + if (action.payload?.status === 422) { + errorDescription = 'Validation Error'; + } else if (action.payload?.error) { + errorDescription = action.payload?.error as string; + } + state.toastQueue.push( makeToast({ title: t('toast.serverError'), status: 'error', - description: - action.payload?.status === 422 ? 'Validation Error' : undefined, + description: errorDescription, }) ); }); diff --git a/invokeai/frontend/web/src/services/api/thunks/session.ts b/invokeai/frontend/web/src/services/api/thunks/session.ts index 5588f25b46..29b032d1c3 100644 --- a/invokeai/frontend/web/src/services/api/thunks/session.ts +++ b/invokeai/frontend/web/src/services/api/thunks/session.ts @@ -60,6 +60,9 @@ type InvokedSessionThunkConfig = { const isErrorWithStatus = (error: unknown): error is { status: number } => isObject(error) && 'status' in error; +const isErrorWithDetail = (error: unknown): error is { detail: string } => + isObject(error) && 'detail' in error; + /** * `SessionsService.invokeSession()` thunk */ @@ -85,7 +88,15 @@ export const sessionInvoked = createAsyncThunk< error: (error as any).body.detail, }); } - return rejectWithValue({ arg, status: response.status, error }); + if (isErrorWithDetail(error) && response.status === 403) { + return rejectWithValue({ + arg, + status: response.status, + error: error.detail + }); + } + if (error) + return rejectWithValue({ arg, status: response.status, error }); } });