From c72315ebec1e37857459dd6d062a3dc003d6ba58 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Guhur Date: Wed, 18 Jan 2023 14:30:58 +0100 Subject: [PATCH] fix: loading ballot --- pages/ballot/[pid]/[[...tid]].tsx | 7 ++++--- services/api.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pages/ballot/[pid]/[[...tid]].tsx b/pages/ballot/[pid]/[[...tid]].tsx index 675d064..2cab24c 100644 --- a/pages/ballot/[pid]/[[...tid]].tsx +++ b/pages/ballot/[pid]/[[...tid]].tsx @@ -36,11 +36,11 @@ export async function getServerSideProps({query: {pid, tid}, locale}) { const [election, ballot, translations] = await Promise.all([ getElection(electionRef), - tid ? getBallot(tid) : new Response(null), + tid ? getBallot(tid) : null, serverSideTranslations(locale, ['resource']), ]); - if ('msg' in election) { + if ('message' in election) { return {notFound: true}; } @@ -66,13 +66,14 @@ export async function getServerSideProps({query: {pid, tid}, locale}) { if (description.randomOrder) { shuffle(election.candidates); } + console.log("BALLOT", ballot) return { props: { ...translations, election, token: tid || null, - previousBallot: ballot, + previousBallot: ballot || null, }, }; } diff --git a/services/api.ts b/services/api.ts index 756e5b7..8ebfc8f 100644 --- a/services/api.ts +++ b/services/api.ts @@ -271,7 +271,7 @@ export const getBallot = async ( }); if (response.status != 200) { - return null; + return {status: response.status, message: "Can not load this ballot"}; } const payload = await response.json();