diff --git a/pages/index.tsx b/pages/index.tsx index ef023a64..c19a924b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -86,7 +86,7 @@ export default function Home({ ) } -export const getServerSideProps: GetServerSideProps = async ({ req, locale, query }) => { +export const getServerSideProps: GetServerSideProps = async ({ req, res, locale, query }) => { // Environment-specific links to UIO, UIO Mobile, and BPO, used by EDD testing // Note: it's not possible to use the NEXT_PUBLIC_ prefix to expose these env vars to the browser // because they're set at build time, and Azure doesn't inject env vars ("App Settings") until runtime @@ -134,6 +134,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: { 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() })