From 073edcd0d5e5bc09b771ffb803f34abbb3f45dea Mon Sep 17 00:00:00 2001 From: SelmaBergstrand <78426277+SelmaBergstrand@users.noreply.github.com> Date: Thu, 28 Nov 2024 09:16:36 +0100 Subject: [PATCH] fix(board): add debugging-info to exceptions in getServerSideProps (#1753) * fix(board): add debugging-info to exceptions in getServerSIdeProps * chore(board): check that parser is not undefined * chore(board): set custom error message as part of exception --- tavla/pages/[id].tsx | 68 ++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/tavla/pages/[id].tsx b/tavla/pages/[id].tsx index 929ddcbce..4591103f5 100644 --- a/tavla/pages/[id].tsx +++ b/tavla/pages/[id].tsx @@ -16,35 +16,61 @@ import { TGetQuayQuery, TStopPlaceQuery } from 'graphql/index' import { isUnsupportedBrowser } from 'utils/browserDetection' import { GetServerSideProps } from 'next' import { SSRQuayQuery, SSRStopPlaceQuery } from 'graphql/ssrQueries' +import * as Sentry from '@sentry/nextjs' export const getServerSideProps: GetServerSideProps = async (context) => { - const { params, req } = context - const { id } = params as { id: string } - const ua = req.headers['user-agent'] || '' - const fetchBoardServerSide = isUnsupportedBrowser(ua) + try { + const { params, req } = context + if (!params || !req) { + Sentry.captureMessage('Missing params or req in getServerSideProps') + return { + notFound: true, + } + } + const { id } = params as { id: string } + const ua = req.headers['user-agent'] || '' + const fetchBoardServerSide = isUnsupportedBrowser(ua) - const board: TBoard | undefined = await getBoard(id) + if (!id) { + Sentry.captureMessage('Missing board ID in getServerSideProps') + return { + notFound: true, + } + } - if (!board) { - return { - notFound: true, + const board: TBoard | undefined = await getBoard(id) + + if (!board) { + Sentry.captureMessage('Board is undefined in getServerSideProps') + return { + notFound: true, + } } - } - const organization = await getOrganizationWithBoard(id) + const organization = await getOrganizationWithBoard(id) - let tileData = null - if (fetchBoardServerSide) { - tileData = await getTileData(board) - } + let tileData = null + if (fetchBoardServerSide) { + tileData = await getTileData(board) + } - return { - props: { - board, - organization, - backend_url: getBackendUrl(), - tileData, - }, + return { + props: { + board, + organization, + backend_url: getBackendUrl(), + tileData, + }, + } + } catch (error) { + Sentry.captureException(error, { + extra: { + message: 'Unknown error occurred in getServerSideProps', + }, + }) + return { + notFound: true, + } } }