Skip to content

Commit 7b68774

Browse files
servie return undefined instead of throwing error
1 parent a77681a commit 7b68774

11 files changed

+88
-82
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +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}`);
17-
if (!response.ok) throw new AppError(`Case with ID '${id}' not found.`, ErrorCodes.SIN_CASE_NOT_FOUND);
18+
if (response.status === 404) return undefined;
1819
return response.json();
1920
},
2021
};

Diff for: 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 {

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

+26-25
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export async function loader({ context, request }: Route.LoaderArgs) {
6767

6868
// TODO: the id will likely come from a path param in the URL?
6969
const personSinCase = await getSinCaseService().getSinCaseById('000000000');
70-
7170
const {
7271
birthDetails,
7372
contactInformation,
@@ -76,40 +75,40 @@ export async function loader({ context, request }: Route.LoaderArgs) {
7675
personalInformation,
7776
previousSin,
7877
primaryDocuments,
79-
// TODO - Check why request details is not displayed
80-
// requestDetails,
8178
secondaryDocument,
82-
} = personSinCase;
79+
} = personSinCase ?? {};
8380

8481
return {
8582
documentTitle: t('protected:send-validation.page-title'),
86-
caseId: personSinCase.caseId,
83+
caseId: personSinCase?.caseId ?? null,
8784
inPersonSINCase: {
8885
primaryDocuments: {
8986
...primaryDocuments,
90-
currentStatusInCanadaName: getLocalizedApplicantStatusInCanadaChoiceById(primaryDocuments.currentStatusInCanada, lang)
91-
.name,
92-
documentTypeName: getLocalizedApplicantPrimaryDocumentChoiceById(primaryDocuments.documentType, lang).name,
93-
genderName: getLocalizedApplicantGenderById(primaryDocuments.gender, lang).name,
87+
currentStatusInCanadaName:
88+
primaryDocuments && getLocalizedApplicantStatusInCanadaChoiceById(primaryDocuments.currentStatusInCanada, lang).name,
89+
documentTypeName:
90+
primaryDocuments && getLocalizedApplicantPrimaryDocumentChoiceById(primaryDocuments.documentType, lang).name,
91+
genderName: primaryDocuments && getLocalizedApplicantGenderById(primaryDocuments.gender, lang).name,
9492
},
9593
secondaryDocument: {
9694
...secondaryDocument,
97-
documentTypeName: getLocalizedApplicantSecondaryDocumentChoiceById(secondaryDocument.documentType, lang).name,
95+
documentTypeName:
96+
secondaryDocument && getLocalizedApplicantSecondaryDocumentChoiceById(secondaryDocument.documentType, lang).name,
9897
},
9998
personalInformation: {
10099
...personalInformation,
101-
genderName: getLocalizedApplicantGenderById(personalInformation.gender, lang).name,
100+
genderName: personalInformation && getLocalizedApplicantGenderById(personalInformation.gender, lang).name,
102101
},
103102
birthDetails: {
104103
...birthDetails,
105-
countryName: getLocalizedCountryById(birthDetails.country, lang).name,
106-
provinceName: birthDetails.province
104+
countryName: birthDetails && getLocalizedCountryById(birthDetails.country, lang).name,
105+
provinceName: birthDetails?.province
107106
? birthDetails.country === serverEnvironment.PP_CANADA_COUNTRY_CODE
108107
? getLocalizedProvinceById(birthDetails.province, lang).name
109108
: birthDetails.province
110109
: undefined,
111110
},
112-
parentDetails: parentDetails.map((parentdetail) => ({
111+
parentDetails: parentDetails?.map((parentdetail) => ({
113112
...parentdetail,
114113
countryName: parentdetail.unavailable
115114
? undefined
@@ -124,26 +123,28 @@ export async function loader({ context, request }: Route.LoaderArgs) {
124123
})),
125124
contactInformation: {
126125
...contactInformation,
127-
preferredLanguageName: getLocalizedLanguageOfCorrespondenceById(contactInformation.preferredLanguage, lang).name,
128-
countryName: getLocalizedCountryById(contactInformation.country, lang).name,
126+
preferredLanguageName:
127+
contactInformation && getLocalizedLanguageOfCorrespondenceById(contactInformation.preferredLanguage, lang).name,
128+
countryName: contactInformation && getLocalizedCountryById(contactInformation.country, lang).name,
129129
provinceName:
130-
contactInformation.country === serverEnvironment.PP_CANADA_COUNTRY_CODE
130+
contactInformation?.country === serverEnvironment.PP_CANADA_COUNTRY_CODE
131131
? getLocalizedProvinceById(contactInformation.province, lang).name
132-
: contactInformation.province,
132+
: contactInformation?.province,
133133
},
134134
previousSin: {
135135
...previousSin,
136-
hasPreviousSinText: getLocalizedApplicantHadSinOptionById(previousSin.hasPreviousSin, lang).name,
136+
hasPreviousSinText: previousSin && getLocalizedApplicantHadSinOptionById(previousSin.hasPreviousSin, lang).name,
137137
},
138138
currentNameInfo: {
139139
...currentNameInfo,
140-
firstName: currentNameInfo.preferredSameAsDocumentName ? primaryDocuments.givenName : currentNameInfo.firstName,
141-
middleName: currentNameInfo.preferredSameAsDocumentName ? undefined : currentNameInfo.middleName,
142-
lastName: currentNameInfo.preferredSameAsDocumentName ? primaryDocuments.lastName : currentNameInfo.lastName,
143-
supportingDocuments: currentNameInfo.preferredSameAsDocumentName ? undefined : currentNameInfo.supportingDocuments,
144-
supportingDocumentsNames: currentNameInfo.preferredSameAsDocumentName
140+
preferredSameAsDocumentName: currentNameInfo?.preferredSameAsDocumentName,
141+
firstName: currentNameInfo?.preferredSameAsDocumentName ? primaryDocuments?.givenName : currentNameInfo?.firstName,
142+
middleName: currentNameInfo?.preferredSameAsDocumentName ? undefined : currentNameInfo?.middleName,
143+
lastName: currentNameInfo?.preferredSameAsDocumentName ? primaryDocuments?.lastName : currentNameInfo?.lastName,
144+
supportingDocuments: currentNameInfo?.preferredSameAsDocumentName ? undefined : currentNameInfo?.supportingDocuments,
145+
supportingDocumentsNames: currentNameInfo?.preferredSameAsDocumentName
145146
? undefined
146-
: currentNameInfo.supportingDocuments.required
147+
: currentNameInfo?.supportingDocuments.required
147148
? currentNameInfo.supportingDocuments.documentTypes.map(
148149
(doc) => getLocalizedApplicantSupportingDocumentTypeById(doc, lang).name,
149150
)

Diff for: frontend/app/routes/protected/sin-application/review-birth-details.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { Address } from '~/components/address';
66
import { DescriptionList, DescriptionListItem } from '~/components/description-list';
77

88
interface ReviewBirthDetailsProps {
9-
city: string | undefined;
10-
provinceName: string | undefined;
11-
countryName: string;
12-
fromMultipleBirth: boolean;
9+
city?: string;
10+
provinceName?: string;
11+
countryName?: string;
12+
fromMultipleBirth?: boolean;
1313
children: ReactNode;
1414
}
1515

@@ -20,13 +20,15 @@ export function ReviewBirthDetails({ city, provinceName, countryName, fromMultip
2020
<h2 className="font-lato text-2xl font-bold">{t('protected:birth-details.page-title')}</h2>
2121
<DescriptionList className="divide-y border-y">
2222
<DescriptionListItem className="py-3" term={t('protected:review.birth-place')}>
23-
<Address
24-
address={{
25-
city: city,
26-
provinceState: provinceName,
27-
country: countryName,
28-
}}
29-
/>
23+
{countryName && (
24+
<Address
25+
address={{
26+
city: city,
27+
provinceState: provinceName,
28+
country: countryName,
29+
}}
30+
/>
31+
)}
3032
</DescriptionListItem>
3133
<DescriptionListItem className="py-3" term={t('protected:review.multiple-birth')}>
3234
<p>{fromMultipleBirth ? t('protected:review.yes') : t('protected:review.no')}</p>

Diff for: frontend/app/routes/protected/sin-application/review-contact-information.tsx

+20-18
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { Address } from '~/components/address';
66
import { DescriptionList, DescriptionListItem } from '~/components/description-list';
77

88
interface ReviewContactInformationProps {
9-
preferredLanguageName: string;
10-
primaryPhoneNumber: string;
11-
secondaryPhoneNumber: string | undefined;
12-
emailAddress: string | undefined;
13-
countryName: string;
14-
address: string;
15-
postalCode: string;
16-
city: string;
17-
provinceName: string | undefined;
9+
preferredLanguageName?: string;
10+
primaryPhoneNumber?: string;
11+
secondaryPhoneNumber?: string;
12+
emailAddress?: string;
13+
countryName?: string;
14+
address?: string;
15+
postalCode?: string;
16+
city?: string;
17+
provinceName?: string;
1818
children: ReactNode;
1919
}
2020

@@ -59,15 +59,17 @@ export function ReviewContactInformation({
5959
</h3>
6060
<DescriptionList className="mt-3 divide-y border-y">
6161
<DescriptionListItem className="py-3" term={t('protected:contact-information.address-label')}>
62-
<Address
63-
address={{
64-
addressLine1: address,
65-
city: city,
66-
provinceState: provinceName,
67-
postalZipCode: postalCode,
68-
country: countryName,
69-
}}
70-
/>
62+
{countryName && (
63+
<Address
64+
address={{
65+
addressLine1: address,
66+
city: city,
67+
provinceState: provinceName,
68+
postalZipCode: postalCode,
69+
country: countryName,
70+
}}
71+
/>
72+
)}
7173
</DescriptionListItem>
7274
</DescriptionList>
7375
</div>

Diff for: frontend/app/routes/protected/sin-application/review-current-name.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { DescriptionList, DescriptionListItem } from '~/components/description-l
66
import { UnorderedList } from '~/components/lists';
77

88
interface ReviewCurrentNameProps {
9-
preferredSameAsDocumentName: boolean;
10-
firstName: string;
11-
middleName: string | undefined;
12-
lastName: string;
13-
supportingDocuments: { required: boolean; documentTypes?: string[] } | undefined;
14-
supportingDocumentsNames: string[] | undefined;
9+
preferredSameAsDocumentName?: boolean;
10+
firstName?: string;
11+
middleName?: string;
12+
lastName?: string;
13+
supportingDocuments?: { required: boolean; documentTypes?: string[] };
14+
supportingDocumentsNames?: string[];
1515
children: ReactNode;
1616
}
1717

Diff for: frontend/app/routes/protected/sin-application/review-parent-details.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Address } from '~/components/address';
66
import { DescriptionList, DescriptionListItem } from '~/components/description-list';
77

88
interface ReviewParentDetailsProps {
9-
parentDetails: (
9+
parentDetails?: (
1010
| {
1111
unavailable: boolean;
1212
givenName?: string;

Diff for: frontend/app/routes/protected/sin-application/review-personal-info.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { DescriptionList, DescriptionListItem } from '~/components/description-l
66
import { UnorderedList } from '~/components/lists';
77

88
interface ReviewPersonalInfoProps {
9-
firstNamePreviouslyUsed: string[] | undefined;
10-
lastNameAtBirth: string;
11-
lastNamePreviouslyUsed: string[] | undefined;
12-
genderName: string;
9+
firstNamePreviouslyUsed?: string[];
10+
lastNameAtBirth?: string;
11+
lastNamePreviouslyUsed?: string[];
12+
genderName?: string;
1313
children: ReactNode;
1414
}
1515

Diff for: frontend/app/routes/protected/sin-application/review-previous-sin.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { useTranslation } from 'react-i18next';
55
import { DescriptionList, DescriptionListItem } from '~/components/description-list';
66

77
interface ReviewPreviousSinProps {
8-
hasPreviousSinText: string;
9-
socialInsuranceNumber: string | undefined;
8+
hasPreviousSinText?: string;
9+
socialInsuranceNumber?: string;
1010
children: ReactNode;
1111
}
1212

Diff for: frontend/app/routes/protected/sin-application/review-primary-docs.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { useTranslation } from 'react-i18next';
55
import { DescriptionList, DescriptionListItem } from '~/components/description-list';
66

77
interface ReviewPrimaryDocsProps {
8-
currentStatusInCanadaName: string;
9-
documentTypeName: string;
10-
registrationNumber: string;
11-
clientNumber: string;
12-
givenName: string;
13-
lastName: string;
14-
dateOfBirth: string;
15-
genderName: string;
16-
citizenshipDate: string;
8+
currentStatusInCanadaName?: string;
9+
documentTypeName?: string;
10+
registrationNumber?: string;
11+
clientNumber?: string;
12+
givenName?: string;
13+
lastName?: string;
14+
dateOfBirth?: string;
15+
genderName?: string;
16+
citizenshipDate?: string;
1717
children: ReactNode;
1818
}
1919

Diff for: frontend/app/routes/protected/sin-application/review-secondary-doc.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { useTranslation } from 'react-i18next';
55
import { DescriptionList, DescriptionListItem } from '~/components/description-list';
66

77
interface ReviewSecondaryDocProps {
8-
documentTypeName: string;
9-
expiryMonth: string;
10-
expiryYear: string;
8+
documentTypeName?: string;
9+
expiryMonth?: string;
10+
expiryYear?: string;
1111
children: ReactNode;
1212
}
1313

0 commit comments

Comments
 (0)