diff --git a/apps/judicial-system/web/messages/Core/errors.ts b/apps/judicial-system/web/messages/Core/errors.ts index 02927f00f07f..b2f48b364cdd 100644 --- a/apps/judicial-system/web/messages/Core/errors.ts +++ b/apps/judicial-system/web/messages/Core/errors.ts @@ -94,6 +94,12 @@ export const errors = defineMessages({ description: 'Notaður sem villuskilaboð þegar ekki gengur að sækja lögmanna skrá', }, + fetchLawyer: { + id: 'judicial.system.core:errors.fetch_lawyer', + defaultMessage: 'Upp kom villa við að sækja lögmann úr lögmanna skrá', + description: + 'Notaður sem villuskilaboð þegar ekki gengur að sækja lögmann úr lögmanna skrá', + }, copyLink: { id: 'judicial.system.core:errors.copy_link', defaultMessage: 'Ekki tókst að afrita hlekk', diff --git a/apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts b/apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts index cb2d452f234c..5d9a9bcdcf03 100644 --- a/apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts +++ b/apps/judicial-system/web/src/utils/hooks/useLawyers/useLawyers.ts @@ -39,6 +39,8 @@ export const useGetLawyer = ( nationalId?: string | null, shouldFetch?: boolean, ): Lawyer | undefined => { + const { formatMessage } = useIntl() + const fetcher = (url: string): Promise => fetch(url).then((res) => { if (!res.ok) { @@ -50,7 +52,7 @@ export const useGetLawyer = ( return res.json() }) - const { data } = useSWR( + const { data, error } = useSWR( nationalId && shouldFetch ? `/api/defender/lawyerRegistry/${nationalId}` : null, @@ -63,5 +65,10 @@ export const useGetLawyer = ( }, ) + if (error) { + toast.error(formatMessage(errorMessages.fetchLawyer)) + return undefined + } + return data }