diff --git a/packages/frontend/src/index.tsx b/packages/frontend/src/index.tsx index a1677235..71a96470 100644 --- a/packages/frontend/src/index.tsx +++ b/packages/frontend/src/index.tsx @@ -13,19 +13,7 @@ import reportWebVitals from './reportWebVitals'; import { GQLClientProvider } from './context/GQLClientContext'; import { SERVER_GQL_PATH } from './constants'; import { Toaster } from 'components/shared/Toast'; - -import Bugsnag from '@bugsnag/js'; -import BugsnagPluginReact from '@bugsnag/plugin-react'; -import BugsnagPerformance from '@bugsnag/browser-performance'; - -const bugsnagApiKey = import.meta.env.VITE_BUGSNAG_API_KEY; -if (bugsnagApiKey) { - Bugsnag.start({ - apiKey: bugsnagApiKey, - plugins: [new BugsnagPluginReact()], - }); - BugsnagPerformance.start({ apiKey: bugsnagApiKey }); -} +import { LogErrorBoundary } from 'utils/log-error'; const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement, @@ -39,12 +27,8 @@ const gqlEndpoint = `${import.meta.env.VITE_SERVER_URL}/${SERVER_GQL_PATH}`; const gqlClient = new GQLClient({ gqlEndpoint }); -const ErrorBoundary = bugsnagApiKey - ? Bugsnag.getPlugin('react')!.createErrorBoundary(React) - : ({ children }: any) => children; - root.render( - + @@ -54,7 +38,7 @@ root.render( , - , + , ); // If you want to start measuring performance in your app, pass a function diff --git a/packages/frontend/src/pages/auth/Login.tsx b/packages/frontend/src/pages/auth/Login.tsx index b590f357..f0b407b5 100644 --- a/packages/frontend/src/pages/auth/Login.tsx +++ b/packages/frontend/src/pages/auth/Login.tsx @@ -58,9 +58,8 @@ export const Login = ({ onDone }: Props) => { } } catch (err: any) { setError(err.message); - console.log(err.message, err.name, err.details); - setProvider(false); logError(err); + setProvider(false); return; } } diff --git a/packages/frontend/src/utils/log-error.ts b/packages/frontend/src/utils/log-error.ts index 96885cc4..1126f4b9 100644 --- a/packages/frontend/src/utils/log-error.ts +++ b/packages/frontend/src/utils/log-error.ts @@ -1,6 +1,33 @@ import Bugsnag from '@bugsnag/js'; +import BugsnagPluginReact from '@bugsnag/plugin-react'; +import BugsnagPerformance from '@bugsnag/browser-performance'; +import React from 'react'; + +const bugsnagApiKey = import.meta.env.VITE_BUGSNAG_API_KEY; + +if (bugsnagApiKey) { + Bugsnag.start({ + apiKey: bugsnagApiKey, + plugins: [new BugsnagPluginReact()], + }); + BugsnagPerformance.start({ apiKey: bugsnagApiKey }); +} + +export const errorLoggingEnabled = !!bugsnagApiKey; + +export const LogErrorBoundary = bugsnagApiKey + ? Bugsnag.getPlugin('react')!.createErrorBoundary(React) + : ({ children }: any) => children; export function logError(error: Error) { + let errors: any[] = [error]; + let safety = 0; + while (errors[errors.length - 1].cause && safety < 10) { + errors.push('::caused by::', errors[errors.length - 1].cause); + safety += 1; + } + console.error(...errors); + if (import.meta.env.VITE_BUGSNAG_API_KEY) { Bugsnag.notify(error); }