@akinon/next 1.82.0-rc.16 → 1.82.0-rc.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 1.82.0-rc.18
4
+
5
+ ### Minor Changes
6
+
7
+ - e4761d2: Refactor import statement for ROUTES in error-page component
8
+
9
+ ## 1.82.0-rc.17
10
+
11
+ ### Minor Changes
12
+
13
+ - e2c6d426: ZERO-2935: Add @sentry/nextjs dependency to akinon-next and remove from projectzeronext
14
+ - 70bc0aed: ZERO-3284: Set tracesSampleRate in Sentry configuration
15
+
3
16
  ## 1.82.0-rc.16
4
17
 
5
18
  ### Minor Changes
package/hooks/index.ts CHANGED
@@ -10,3 +10,4 @@ export * from './use-mobile-iframe-handler';
10
10
  export * from './use-payment-options';
11
11
  export * from './use-pagination';
12
12
  export * from './use-message-listener';
13
+ export * from './use-sentry-uncaught-errors';
@@ -0,0 +1,24 @@
1
+ import { useEffect } from 'react';
2
+ import * as Sentry from '@sentry/nextjs';
3
+ import { ClientLogType } from '@akinon/next/sentry';
4
+
5
+ export const useSentryUncaughtErrors = (error: Error & { digest?: string }) => {
6
+ useEffect(() => {
7
+ Sentry.withScope(function (scope) {
8
+ scope.setLevel('fatal');
9
+ scope.setTags({
10
+ APP_TYPE: 'ProjectZeroNext',
11
+ TYPE: 'Client',
12
+ LOG_TYPE: ClientLogType.UNCAUGHT_ERROR_PAGE
13
+ });
14
+ scope.setExtra('error', error);
15
+
16
+ const error_ = new Error('FATAL: Uncaught client error');
17
+ error_.name = 'UNCAUGHT_ERROR_PAGE';
18
+
19
+ Sentry.captureException(error_, {
20
+ fingerprint: ['UNCAUGHT_ERROR_PAGE', error.digest]
21
+ });
22
+ });
23
+ }, [error]);
24
+ };
@@ -1,4 +1,5 @@
1
1
  import { initSentry } from '../sentry';
2
+ import * as Sentry from '@sentry/nextjs';
2
3
 
3
4
  export async function register() {
4
5
  if (process.env.NEXT_RUNTIME === 'nodejs') {
@@ -10,3 +11,5 @@ export async function register() {
10
11
  initSentry('Edge');
11
12
  }
12
13
  }
14
+
15
+ export const onRequestError = Sentry.captureRequestError;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.82.0-rc.16",
4
+ "version": "1.82.0-rc.18",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -21,6 +21,7 @@
21
21
  "@opentelemetry/semantic-conventions": "1.19.0",
22
22
  "@reduxjs/toolkit": "1.9.7",
23
23
  "@neshca/cache-handler": "1.9.0",
24
+ "@sentry/nextjs": "9.5.0",
24
25
  "cross-spawn": "7.0.3",
25
26
  "generic-pool": "3.9.0",
26
27
  "react-redux": "8.1.3",
@@ -30,7 +31,7 @@
30
31
  "set-cookie-parser": "2.6.0"
31
32
  },
32
33
  "devDependencies": {
33
- "@akinon/eslint-plugin-projectzero": "1.82.0-rc.16",
34
+ "@akinon/eslint-plugin-projectzero": "1.82.0-rc.18",
34
35
  "@types/react-redux": "7.1.30",
35
36
  "@types/set-cookie-parser": "2.4.7",
36
37
  "@typescript-eslint/eslint-plugin": "6.7.4",
package/sentry/index.ts CHANGED
@@ -30,7 +30,7 @@ export const initSentry = (
30
30
  TYPE: type
31
31
  }
32
32
  },
33
- tracesSampleRate: 1.0,
33
+ tracesSampleRate: 0,
34
34
  integrations: [],
35
35
  beforeSend: (event, hint) => {
36
36
  if (
@@ -0,0 +1,93 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useLocalization } from '../hooks';
3
+ import { Button, Link } from '../components';
4
+ import { ROUTES } from 'routes';
5
+
6
+ export default function PzErrorPage({
7
+ error,
8
+ reset
9
+ }: {
10
+ error: Error & { digest?: string; isServerError?: boolean };
11
+ reset: () => void;
12
+ }) {
13
+ const [isServerError, setIsServerError] = useState(false);
14
+
15
+ useEffect(() => {
16
+ if ('isServerError' in error) {
17
+ setIsServerError(true);
18
+ return;
19
+ }
20
+
21
+ setIsServerError(!!error.digest);
22
+ }, [error]);
23
+
24
+ return isServerError ? (
25
+ <ServerErrorUI />
26
+ ) : (
27
+ <ClientErrorUI error={error} reset={reset} />
28
+ );
29
+ }
30
+
31
+ function ClientErrorUI({
32
+ error,
33
+ reset
34
+ }: {
35
+ error: Error & { digest?: string };
36
+ reset: () => void;
37
+ }) {
38
+ const { t } = useLocalization();
39
+
40
+ const errorMessage = error?.message || 'Unknown error';
41
+
42
+ return (
43
+ <section className="text-center px-6 my-14 md:px-0 md:m-14">
44
+ <div className="text-4xl font-bold md:text-6xl text-red-500">Oops!</div>
45
+ <h1 className="text-lg md:text-xl mt-4">
46
+ {t('common.client_error.title')}
47
+ </h1>
48
+ <p className="text-lg md:text-xl mt-2">
49
+ {t('common.client_error.description')}
50
+ </p>
51
+
52
+ <div className="mt-4 mx-auto max-w-lg">
53
+ <p className="text-xs text-gray-600 font-mono bg-gray-100 p-3 rounded overflow-auto text-left">
54
+ <span className="font-semibold">Error:</span> {errorMessage}
55
+ </p>
56
+ </div>
57
+
58
+ <div className="mt-6 flex flex-col gap-4 items-center justify-center">
59
+ <Link href={ROUTES.HOME} className="text-lg underline">
60
+ {t('common.client_error.link_text')}
61
+ </Link>
62
+ <Button onClick={reset} className="text-lg w-28">
63
+ {t('common.try_again')}
64
+ </Button>
65
+ </div>
66
+ </section>
67
+ );
68
+ }
69
+
70
+ function ServerErrorUI() {
71
+ const { t } = useLocalization();
72
+
73
+ const reloadPage = () => {
74
+ window.location.reload();
75
+ };
76
+
77
+ return (
78
+ <section className="text-center px-6 my-14 md:px-0 md:m-14">
79
+ <div className="text-7xl font-bold md:text-8xl">500</div>
80
+ <h1 className="text-lg md:text-xl"> {t('common.page_500.title')} </h1>
81
+ <p className="text-lg md:text-xl"> {t('common.page_500.description')} </p>
82
+
83
+ <div className="mt-6 flex flex-col gap-4 items-center justify-center">
84
+ <Link href={ROUTES.HOME} className="text-lg underline">
85
+ {t('common.page_500.link_text')}
86
+ </Link>
87
+ <Button onClick={reloadPage} className="text-lg w-28">
88
+ {t('common.try_again')}
89
+ </Button>
90
+ </div>
91
+ </section>
92
+ );
93
+ }