Advertisement
Guest User

Untitled

a guest
May 7th, 2018
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2. import { JL } from "jsnlog";
  3.  
  4. JL.setOptions({
  5.   defaultAjaxUrl: `//${window.location.hostname}:${process.env.REACT_APP_LOGGER_PORT || 3334}/jsnlog.logger`
  6. });
  7.  
  8. class ErrorBoundary extends Component {
  9.   constructor(props) {
  10.     super(props);
  11.     this.state = { error: null };
  12.   }
  13.  
  14.   componentDidCatch(error, errorInfo) {
  15.     this.setState({ error });
  16.     JL("reactAppError").fatalException(
  17.       {
  18.         msg: "Uncaught Exception",
  19.         agent: window.navigator.userAgent,
  20.         errorMsg: errorInfo,
  21.         url: window.location.href,
  22.         userId: window.userId
  23.       },
  24.       error
  25.     );
  26.   }
  27.  
  28.   render() {
  29.     if (this.state.error) {
  30.       //render fallback UI
  31.       return (
  32.         <div className="snap text-center">
  33.           <p>We're sorry — something's gone wrong.</p>
  34.           <p>Our team has been notified</p>
  35.         </div>
  36.       );
  37.     } else {
  38.       //when there's not an error, render children untouched
  39.       return this.props.children;
  40.     }
  41.   }
  42. }
  43.  
  44. export default ErrorBoundary;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement