Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from "react";
- import { JL } from "jsnlog";
- JL.setOptions({
- defaultAjaxUrl: `//${window.location.hostname}:${process.env.REACT_APP_LOGGER_PORT || 3334}/jsnlog.logger`
- });
- class ErrorBoundary extends Component {
- constructor(props) {
- super(props);
- this.state = { error: null };
- }
- componentDidCatch(error, errorInfo) {
- this.setState({ error });
- JL("reactAppError").fatalException(
- {
- msg: "Uncaught Exception",
- agent: window.navigator.userAgent,
- errorMsg: errorInfo,
- url: window.location.href,
- userId: window.userId
- },
- error
- );
- }
- render() {
- if (this.state.error) {
- //render fallback UI
- return (
- <div className="snap text-center">
- <p>We're sorry — something's gone wrong.</p>
- <p>Our team has been notified</p>
- </div>
- );
- } else {
- //when there's not an error, render children untouched
- return this.props.children;
- }
- }
- }
- export default ErrorBoundary;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement