Skip to content

Commit

Permalink
Add error handling to get single lawyer
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsson committed Jan 9, 2025
1 parent 303da94 commit fd6946a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/judicial-system/web/messages/Core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const useGetLawyer = (
nationalId?: string | null,
shouldFetch?: boolean,
): Lawyer | undefined => {
const { formatMessage } = useIntl()

const fetcher = (url: string): Promise<Lawyer> =>
fetch(url).then((res) => {
if (!res.ok) {
Expand All @@ -50,7 +52,7 @@ export const useGetLawyer = (
return res.json()
})

const { data } = useSWR<Lawyer>(
const { data, error } = useSWR<Lawyer>(
nationalId && shouldFetch
? `/api/defender/lawyerRegistry/${nationalId}`
: null,
Expand All @@ -63,5 +65,10 @@ export const useGetLawyer = (
},
)

if (error) {
toast.error(formatMessage(errorMessages.fetchLawyer))
return undefined
}

return data
}

0 comments on commit fd6946a

Please sign in to comment.