From 16bb3c44e278d35056dd25f4b96b71b6dcd0143e Mon Sep 17 00:00:00 2001 From: Rocket ! Date: Mon, 23 Aug 2021 18:20:09 -0700 Subject: [PATCH 1/2] Set the response status code when there are errors. --- pages/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pages/index.tsx b/pages/index.tsx index 1b748239..00a09e0c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -84,7 +84,7 @@ export default function Home({ ) } -export const getServerSideProps: GetServerSideProps = async ({ req, locale, query }) => { +export const getServerSideProps: GetServerSideProps = async ({ req, res, locale, query }) => { const isProd = process.env.NODE_ENV === 'production' const logger = isProd ? pino({}) : pino({ prettyPrint: true }) logger.info(req) @@ -123,6 +123,11 @@ export const getServerSideProps: GetServerSideProps = async ({ req, locale, quer // that in our links back out to UIO. const userArrivedFromUioMobile = query?.from === 'uiom' + // If there is an errorCode, set the response statusCode to match. + if (errorCode) { + res.statusCode = errorCode + } + // Return Props. return { props: { From 58db8e2dbce540ea62f348095e3abae03057356f Mon Sep 17 00:00:00 2001 From: Rocket ! Date: Tue, 24 Aug 2021 15:58:53 -0700 Subject: [PATCH 2/2] Fix tests. --- tests/pages/indexServerSide.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/pages/indexServerSide.test.ts b/tests/pages/indexServerSide.test.ts index 8a71e3c9..20b37b29 100644 --- a/tests/pages/indexServerSide.test.ts +++ b/tests/pages/indexServerSide.test.ts @@ -17,11 +17,15 @@ describe('Main component server side logic', () => { // empty header headers: {}, }, + res: { + statusCode: null, + }, } const result: GetServerSideProps = await getServerSideProps(context as GetServerSidePropsContext) const props: HomeProps = result.props as HomeProps expect(props.errorCode).toBe(500) + expect(context.res.statusCode).toBe(500) restore() })