From 58e67617ddaa448b3e75677805846f178c2943c8 Mon Sep 17 00:00:00 2001 From: Tobias Lins Date: Thu, 12 Oct 2023 08:20:51 +0200 Subject: [PATCH 1/3] Add error tracking example --- apps/nextjs/app/errors/error.tsx | 14 ++++++++++++++ apps/nextjs/app/errors/page.tsx | 10 ++++++++++ apps/nextjs/app/layout.tsx | 3 +++ 3 files changed, 27 insertions(+) create mode 100644 apps/nextjs/app/errors/error.tsx create mode 100644 apps/nextjs/app/errors/page.tsx diff --git a/apps/nextjs/app/errors/error.tsx b/apps/nextjs/app/errors/error.tsx new file mode 100644 index 0000000..0cbf448 --- /dev/null +++ b/apps/nextjs/app/errors/error.tsx @@ -0,0 +1,14 @@ +'use client'; +import { useEffect } from 'react'; +import { track } from '@vercel/analytics'; + +export default function Error({ error }: { error: Error; reset: () => void }) { + useEffect(() => { + track('thrown-error', { + message: error.message, + time: new Date().toLocaleString(), + }); + }, [error.message]); + + return
Error
; +} diff --git a/apps/nextjs/app/errors/page.tsx b/apps/nextjs/app/errors/page.tsx new file mode 100644 index 0000000..3de1d5e --- /dev/null +++ b/apps/nextjs/app/errors/page.tsx @@ -0,0 +1,10 @@ +'use client'; +import { useEffect } from 'react'; + +export default function ErrorPage() { + useEffect(() => { + throw new Error('Error!'); + }, []); + + return
I should error
; +} diff --git a/apps/nextjs/app/layout.tsx b/apps/nextjs/app/layout.tsx index 27c627c..629d43a 100644 --- a/apps/nextjs/app/layout.tsx +++ b/apps/nextjs/app/layout.tsx @@ -1,3 +1,5 @@ +import { Analytics } from '@vercel/analytics/react'; + export const metadata = { title: 'Next.js', description: 'Generated by Next.js', @@ -11,6 +13,7 @@ export default function RootLayout({ return ( {children} + ); } From 9bf938d24c2a5b7b6c904f4506427022bc5fb22f Mon Sep 17 00:00:00 2001 From: Tobias Lins Date: Thu, 12 Oct 2023 08:24:22 +0200 Subject: [PATCH 2/3] Add logs --- apps/nextjs/app/errors/error.tsx | 1 + apps/nextjs/app/layout.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/nextjs/app/errors/error.tsx b/apps/nextjs/app/errors/error.tsx index 0cbf448..733d29a 100644 --- a/apps/nextjs/app/errors/error.tsx +++ b/apps/nextjs/app/errors/error.tsx @@ -4,6 +4,7 @@ import { track } from '@vercel/analytics'; export default function Error({ error }: { error: Error; reset: () => void }) { useEffect(() => { + console.log('throwing error'); track('thrown-error', { message: error.message, time: new Date().toLocaleString(), diff --git a/apps/nextjs/app/layout.tsx b/apps/nextjs/app/layout.tsx index 629d43a..a15e54f 100644 --- a/apps/nextjs/app/layout.tsx +++ b/apps/nextjs/app/layout.tsx @@ -12,8 +12,8 @@ export default function RootLayout({ }) { return ( - {children} + {children} ); } From e38e9e3837850b984037bdc7ea297f5b1633d625 Mon Sep 17 00:00:00 2001 From: Tobias Lins Date: Thu, 12 Oct 2023 08:31:10 +0200 Subject: [PATCH 3/3] Remove log --- apps/nextjs/app/errors/error.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/nextjs/app/errors/error.tsx b/apps/nextjs/app/errors/error.tsx index 733d29a..0cbf448 100644 --- a/apps/nextjs/app/errors/error.tsx +++ b/apps/nextjs/app/errors/error.tsx @@ -4,7 +4,6 @@ import { track } from '@vercel/analytics'; export default function Error({ error }: { error: Error; reset: () => void }) { useEffect(() => { - console.log('throwing error'); track('thrown-error', { message: error.message, time: new Date().toLocaleString(),