Skip to content

Instantly share code, notes, and snippets.

@OlivierJM
Created March 25, 2019 16:56
Show Gist options
  • Save OlivierJM/a7ec8a791bfbdcea3b02b3790ab63ea3 to your computer and use it in GitHub Desktop.
Save OlivierJM/a7ec8a791bfbdcea3b02b3790ab63ea3 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { PropTypes } from 'prop-types';
import { Meteor } from 'meteor/meteor';
import { formatText } from '../utils/utils';
export default class ErrorBoundary extends Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
this.setState({ hasError: true, info });
Meteor.call('logger', formatText(error, Meteor.userId(), 'error-boundary'), 'error');
}
takeBack = e => {
e.preventDefault();
return history.go(-1);
};
render() {
const { hasError } = this.state;
const { children } = this.props;
if (hasError) {
return (
<>
<h1 className="notFoundHead">
Error Happened <i className="fa fa-frown-o" />
</h1>
<h3 className="notFound">
{' '}
Sorry it seems like something went wrong <br />Try
<a href="" onClick={e => this.takeBack(e)}>
{' '}
go back
</a>
</h3>
</>
);
}
return children;
}
}
ErrorBoundary.propTypes = {
children: PropTypes.node.isRequired,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment