Skip to content

Commit

Permalink
fix(branch info): handle 404 error
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen committed Jul 6, 2024
1 parent 5965820 commit e52b391
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/app/info/branch/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@ async function getBranchData(branchId: string): Promise<BranchData> {
const now = moment().startOf("day").format("DDMMYYYYHHmm");
const openingHoursUrl = `${BL_CONFIG.collection.openingHour}?branch=${branchId}&from=>${now}`;
const branchData: BranchData = { branch: null, openingHours: [] };
const [branchResult, openingHoursResult] = await Promise.allSettled([
BlFetcher.get<Branch[]>(branchUrl),
BlFetcher.get<OpeningHour[]>(openingHoursUrl),
]);

if (branchResult.status === "fulfilled") {
branchData.branch = branchResult.value[0] ?? null;
} else {
assertBlApiError(branchResult.reason);
try {
const branches = await BlFetcher.get<Branch[]>(branchUrl);
branchData.branch = branches[0] ?? null;
} catch (error) {
assertBlApiError(error);
}

if (openingHoursResult.status === "fulfilled") {
branchData.openingHours = openingHoursResult.value;
} else {
assertBlApiError(openingHoursResult.reason);
try {
const openingHoursResult =
await BlFetcher.get<OpeningHour[]>(openingHoursUrl);
branchData.openingHours = openingHoursResult ?? [];
} catch (error) {
assertBlApiError(error);
}

return branchData;
Expand Down

0 comments on commit e52b391

Please sign in to comment.