diff --git a/src/layout/SigneeList/SigneeListComponent.tsx b/src/layout/SigneeList/SigneeListComponent.tsx index b3a93e912..e04cf8348 100644 --- a/src/layout/SigneeList/SigneeListComponent.tsx +++ b/src/layout/SigneeList/SigneeListComponent.tsx @@ -2,7 +2,8 @@ import React from 'react'; import { useParams } from 'react-router-dom'; import { queryOptions, useQuery } from '@tanstack/react-query'; -import { z } from 'zod'; +import { isAxiosError } from 'axios'; +import { z, ZodError } from 'zod'; import { AppTable } from 'src/app-components/Table/Table'; import { Caption } from 'src/components/form/caption/Caption'; @@ -45,10 +46,17 @@ async function fetchSigneeList(partyId: string, instanceGuid: string): Promise (a.name ?? '').localeCompare(b.name ?? '')); + + return { errors: null, data: sortedSigneeStates }; + } catch (error: unknown) { + if (error instanceof ZodError) { + // // TODO: alarm? telemetri? + window.logErrorOnce( + `Did not get the expected response from the server. The response didn't match the expected schema: \n${error}`, + ); return { data: null, errors: [ @@ -65,16 +73,14 @@ async function fetchSigneeList(partyId: string, instanceGuid: string): Promise (a.name ?? '').localeCompare(b.name ?? '')); + if (isAxiosError(error)) { + const parsed = problemDetailsSchema.safeParse(error.response?.data); - return { errors: null, data: sortedSigneeStates }; - } catch (error) { - const parsed = problemDetailsSchema.safeParse(error.response.data); - - if (!parsed.success) { - throw new Error('signee_list.unknown_api_error'); + if (parsed.success) { + throw new Error(parsed.data.detail); + } } - throw new Error(parsed.data.detail); + throw new Error('signee_list.unknown_api_error'); } }