1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/layout/Error/Error.tsx
Nuno Góis 6be21fc1bd
feat: track uncaught UI errors in plausible (#2860)
https://linear.app/unleash/issue/2-567/add-plausible-tracking-to-unknown-uncaught-frontend-errors

Based on the discussion from
https://github.com/Unleash/unleash/pull/2851, something like this could
help us track uncaught/unknown errors on the frontend.

Just a quick suggestion, since there might be something better we could
use for this.
2023-01-10 10:33:56 +00:00

59 lines
1.8 KiB
TypeScript

import { useEffect, VFC } from 'react';
import { useNavigate } from 'react-router-dom';
import { Box } from '@mui/material';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
interface IErrorProps {
error: Error;
}
export const Error: VFC<IErrorProps> = ({ error }) => {
const navigate = useNavigate();
const { trackEvent } = usePlausibleTracker();
useEffect(() => {
const { message, stack = 'unknown' } = error;
trackEvent('unknown_ui_error', {
props: {
location: window?.location?.href || 'unknown',
message,
stack,
},
});
}, []);
return (
<Box sx={{ backgroundColor: 'neutral.light', height: '100%', p: 4 }}>
<Dialogue
open={true}
title="Something went wrong"
primaryButtonText="Go back"
onClick={() => {
navigate('/');
window?.location?.reload();
}}
secondaryButtonText="Reload this page"
onClose={() => {
window?.location?.reload();
}}
maxWidth="xl"
>
<Box component="pre" sx={{ color: 'error.main' }}>
{error.message}
</Box>
<ConditionallyRender
condition={Boolean(error.stack)}
show={
<Box component="pre" sx={{ color: 'error.main' }}>
{error.stack}
</Box>
}
/>
</Dialogue>
</Box>
);
};