fix error detail in toast

This commit is contained in:
Mary Hipp
2023-08-10 13:38:52 -04:00
committed by psychedelicious
parent 50415450d8
commit 3b6e425e17
2 changed files with 21 additions and 3 deletions

View File

@ -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 });
}
});