Skip to content

Commit 8738ef6

Browse files
servie return undefined instead of throwing error (#484)
1 parent a77681a commit 8738ef6

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

frontend/app/.server/domain/multi-channel/case-api-service-default.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ export function getDefaultSinCaseService(): SinCaseService {
88
return {
99
getSinCases: async (): Promise<SinCaseDto[]> => {
1010
const response = await fetch(`${serverEnvironment.INTEROP_SIN_REG_API_BASE_URL}/cases`);
11+
if (response.status === 404) return [];
1112
if (!response.ok) throw new AppError(`Cases not found.`, ErrorCodes.SIN_CASE_NOT_FOUND);
1213
return response.json();
1314
},
1415

15-
getSinCaseById: async (id: string): Promise<SinCaseDto> => {
16+
getSinCaseById: async (id: string): Promise<SinCaseDto | undefined> => {
1617
const response = await fetch(`${serverEnvironment.INTEROP_SIN_REG_API_BASE_URL}/cases/${id}`);
18+
if (response.status === 404) return undefined;
1719
if (!response.ok) throw new AppError(`Case with ID '${id}' not found.`, ErrorCodes.SIN_CASE_NOT_FOUND);
1820
return response.json();
1921
},

frontend/app/.server/domain/multi-channel/case-api-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { serverEnvironment } from '~/.server/environment';
55

66
export type SinCaseService = {
77
getSinCases(): Promise<SinCaseDto[]>;
8-
getSinCaseById(id: string): Promise<SinCaseDto>;
8+
getSinCaseById(id: string): Promise<SinCaseDto | undefined>;
99
};
1010

1111
export function getSinCaseService(): SinCaseService {

frontend/app/routes/protected/multi-channel/send-validation.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { InlineLink } from '~/components/links';
2626
import { PageTitle } from '~/components/page-title';
2727
import { AppError } from '~/errors/app-error';
2828
import { ErrorCodes } from '~/errors/error-codes';
29+
import { HttpStatusCodes } from '~/errors/http-status-codes';
2930
import { getTranslation } from '~/i18n-config.server';
3031
import { handle as parentHandle } from '~/routes/protected/person-case/layout';
3132
import { ReviewBirthDetails } from '~/routes/protected/sin-application/review-birth-details';
@@ -68,6 +69,12 @@ export async function loader({ context, request }: Route.LoaderArgs) {
6869
// TODO: the id will likely come from a path param in the URL?
6970
const personSinCase = await getSinCaseService().getSinCaseById('000000000');
7071

72+
if (personSinCase === undefined) {
73+
throw new Response(JSON.stringify({ status: HttpStatusCodes.NOT_FOUND, message: 'Case not found' }), {
74+
status: HttpStatusCodes.NOT_FOUND,
75+
});
76+
}
77+
7178
const {
7279
birthDetails,
7380
contactInformation,

0 commit comments

Comments
 (0)