Skip to content

Commit

Permalink
better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tonymtz committed May 2, 2024
1 parent d2a47b9 commit 699e364
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tomatoro",
"version": "3.0.180",
"version": "3.0.181",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
21 changes: 13 additions & 8 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetStaticProps } from 'next'
import Image from 'next/image'
import React from 'react'
Expand All @@ -14,8 +15,7 @@ const fallbackPage: BasicPage = {
id: 'fallback',
attributes: {
title: 'Oops! 🍅 Time\'s Up!',
// eslint-disable-next-line max-len
content: 'We couldn\'t find the page you\'re looking for.\n\nLet\'s get you back on track!\n\n[Return to Tomatoro Home](/)',
content: 'We couldn\'t find the page you\'re looking for.\n\nLet\'s get you back on track!\n',
createdAt: '2023-04-29T00:35:43.151Z',
updatedAt: '2023-04-29T00:40:25.617Z',
publishedAt: '2023-04-29T00:40:25.617Z',
Expand All @@ -31,14 +31,19 @@ export const getStaticProps: GetStaticProps<
{ page: BasicPage },
{}
> = async ({ locale }) => {
const fieldParameters = ['seo', 'seo.metaImage', 'hero'].join('&populate[]=')
let page = await getSingleType<BasicPage>('error-404', fieldParameters, locale)
try {
const fieldParameters = ['seo', 'seo.metaImage', 'hero'].join('&populate[]=')
let page = await getSingleType<BasicPage>('error-404', fieldParameters, locale)

if (!page) {
page = fallbackPage
}
if (!page) {
page = fallbackPage
}

return { props: { page } }
return { props: { page } }
} catch (e) {
Sentry.captureException(e)
return { props: { page: fallbackPage } }
}
}

export default function Custom404 ({ page }: { page: Post }) {
Expand Down
2 changes: 2 additions & 0 deletions pages/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetStaticProps } from 'next'
import React from 'react'
import { Grid, Heading } from 'theme-ui'
Expand Down Expand Up @@ -39,6 +40,7 @@ export const getStaticProps: GetStaticProps<

return { props: { post, banners } }
} catch (e) {
Sentry.captureException(e)
return { notFound: true }
}
}
Expand Down
2 changes: 2 additions & 0 deletions pages/blog/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'
import React from 'react'
import { Grid, Heading } from 'theme-ui'
Expand All @@ -22,6 +23,7 @@ export const getServerSideProps: GetServerSideProps<

return { props: { post } }
} catch (e) {
Sentry.captureException(e)
return { notFound: true }
}
}
Expand Down
4 changes: 3 additions & 1 deletion pages/blog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'
import React from 'react'
import { Grid, Heading } from 'theme-ui'
Expand All @@ -12,7 +13,8 @@ export const getServerSideProps: GetServerSideProps<{}> = async ({ locale = 'en'
const posts = await getAllPosts(locale as Locale)
return { props: { posts } }
} catch (e) {
throw new Error('[getServerSideProps] getAllPosts')
Sentry.captureException(e)
return { props: { posts: [] } }
}
}

Expand Down
11 changes: 9 additions & 2 deletions pages/faq.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'
import React from 'react'
import { Grid, Heading } from 'theme-ui'
Expand All @@ -20,11 +21,17 @@ export const getServerSideProps: GetServerSideProps<{}> = async ({ locale }) =>
])
return { props: { questions, page } }
} catch (e) {
throw new Error('[getServerSideProps] getUpdates')
Sentry.captureException(e)
return { props: { questions: [], page: null } }
}
}

export default function Faq ({ page, questions }: { page: BasicPage, questions: Question[] }) {
interface RouteProps {
questions: Question[]
page: BasicPage | null
}

export default function Faq ({ page, questions }: RouteProps) {
if (!page) {
return null
}
Expand Down
4 changes: 3 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'
import React from 'react'
import { Box, Divider } from 'theme-ui'
Expand All @@ -18,7 +19,8 @@ export const getServerSideProps: GetServerSideProps<{}> = async () => {
const banners = await getBanners('home')
return { props: { banners } }
} catch (e) {
throw new Error('[getServerSideProps] getBanners')
Sentry.captureException(e)
return { props: { banners: [] } }
}
}

Expand Down
4 changes: 3 additions & 1 deletion pages/news.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'
import useTranslation from 'next-translate/useTranslation'
import React from 'react'
Expand All @@ -15,7 +16,8 @@ export const getServerSideProps: GetServerSideProps<{}> = async ({ locale }) =>
const sortedUpdates = updates.sort((a, b) => b.attributes.date.localeCompare(a.attributes.date))
return { props: { updates: sortedUpdates } }
} catch (e) {
throw new Error('[getServerSideProps] getUpdates')
Sentry.captureException(e)
return { props: { updates: [] } }
}
}

Expand Down
11 changes: 9 additions & 2 deletions pages/preguntas-frecuentes.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'
import React from 'react'
import { Grid, Heading } from 'theme-ui'
Expand All @@ -20,11 +21,17 @@ export const getServerSideProps: GetServerSideProps<{}> = async ({ locale }) =>
])
return { props: { questions, page } }
} catch (e) {
throw new Error('[getServerSideProps] getUpdates')
Sentry.captureException(e)
return { props: { questions: [], page: null } }
}
}

export default function Faq ({ page, questions }: { page: BasicPage, questions: Question[] }) {
interface RouteProps {
questions: Question[]
page: BasicPage | null
}

export default function Faq ({ page, questions }: RouteProps) {
if (!page) {
return null
}
Expand Down
6 changes: 4 additions & 2 deletions pages/sitemap.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/nextjs'
import { GetServerSideProps } from 'next'

import { getAllPosts } from '~/utils/cms.api'
Expand Down Expand Up @@ -54,7 +55,7 @@ export const getServerSideProps: GetServerSideProps<{}> = async ({ res }) => {
getAllPosts('es'),
])
const sitemap = generateSiteMap({
posts: { en: postsEn, es: postsEs } ,
posts: { en: postsEn, es: postsEs },
domain: 'https://tomatoro.com',
staticPages,
})
Expand All @@ -67,7 +68,8 @@ export const getServerSideProps: GetServerSideProps<{}> = async ({ res }) => {
props: {},
}
} catch (e) {
throw new Error('[getServerSideProps] sitemap')
Sentry.captureException(e)
return { props: {} }
}
}

Expand Down

0 comments on commit 699e364

Please sign in to comment.