generated from Borodutch/frontend-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from BigWhaleLabs/add-sentry
add sentry
- Loading branch information
Showing
11 changed files
with
340 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
export default function handleError(error: unknown) { | ||
let output = '' | ||
if (error instanceof Error) output = error.message | ||
if (typeof error === 'string') output = error | ||
import Sentry from 'helpers/initSentry' | ||
import parseError from 'helpers/parseError' | ||
|
||
if (output.includes('to BigInt') || output.includes('invalid BigInt')) | ||
return 'Please provide a valid token' | ||
if (output.includes('The leaf')) return "Looks like you're not invited" | ||
return output | ||
export default function handleError({ | ||
e, | ||
sendToSentry = true, | ||
}: { | ||
e: unknown | ||
sendToSentry?: boolean | ||
}) { | ||
console.error('Handled error\n', e) | ||
|
||
const message = parseError(e) | ||
if (sendToSentry) { | ||
if (e instanceof Error) { | ||
Sentry.captureException(e) | ||
} else { | ||
Sentry.captureException(new Error(message, { cause: e })) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as Sentry from '@sentry/react' | ||
import env from 'helpers/env' | ||
|
||
export function initSentry() { | ||
Sentry.init({ | ||
dsn: env.VITE_SENTRY_DSN, | ||
environment: process.env.NODE_ENV, | ||
tracesSampleRate: 1.0, | ||
}) | ||
} | ||
|
||
export default Sentry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { isAxiosError } from 'axios' | ||
|
||
interface MessageObject { | ||
message: string | ||
} | ||
|
||
export function stringifyError(e: unknown) { | ||
if (typeof e === 'string') return e | ||
if (isAxiosError(e) && e.response?.data?.message) | ||
return e.response?.data?.message | ||
if (e instanceof Error || isMessageObject(e)) return e.message | ||
return e | ||
} | ||
|
||
function isMessageObject(e: unknown): e is MessageObject { | ||
return (e as MessageObject)?.message !== undefined | ||
} | ||
|
||
export default function parseError(e: unknown, fallbackError?: string) { | ||
const result = stringifyError(e) | ||
return typeof result === 'string' | ||
? result | ||
: fallbackError || 'An unknown error occurred, check the logs' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import 'index.css' | ||
import { initSentry } from 'helpers/initSentry' | ||
import { render } from 'preact' | ||
import App from 'App' | ||
|
||
initSentry() | ||
render(<App />, document.getElementById('root') as Element) |
Oops, something went wrong.