web.lib.core.components.sentry-boundary.tsx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of code-quarkus Show documentation
Show all versions of code-quarkus Show documentation
Customize a Web Interface to generate Quarkus starter projects.
import * as React from 'react';
import * as Sentry from '@sentry/browser';
import { Button } from 'react-bootstrap';
interface SentryBoundaryProps {
sentryDSN?: string;
environment: string;
children?: React.ReactNode;
}
export class SentryBoundary extends React.Component {
constructor(props: SentryBoundaryProps) {
super(props);
this.state = { error: undefined };
if (props.sentryDSN) {
console.info('Sentry is enabled');
Sentry.init({
dsn: props.sentryDSN,
environment: props.environment,
});
} else {
console.info('Sentry is disabled');
}
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
if (this.props.sentryDSN) {
this.setState({ error });
Sentry.withScope(scope => {
Object.keys(errorInfo).forEach(key => {
// @ts-ignore
scope.setExtra(key, errorInfo[key]);
});
Sentry.captureException(error);
});
}
}
render() {
if (this.state.error) {
return (
);
} else {
return <>{this.props.children}>;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy