2018-11-04 16:32:34 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
ErrorCatcher
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
<Components.ErrorCatcher>
|
|
|
|
<YourComponentTree />
|
|
|
|
</Components.ErrorCatcher>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { Components, registerComponent, withCurrentUser } from 'meteor/vulcan:core';
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { Errors } from '../modules/errors.js';
|
|
|
|
|
|
|
|
class ErrorCatcher extends Component {
|
|
|
|
state = {
|
|
|
|
error: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidCatch = (error, errorInfo) => {
|
2018-12-10 15:49:25 +09:00
|
|
|
const { currentUser, siteData = {} } = this.props;
|
2018-11-24 09:56:41 +09:00
|
|
|
const { sourceVersion } = siteData;
|
2018-11-04 16:32:34 +09:00
|
|
|
this.setState({ error });
|
|
|
|
Errors.log({
|
|
|
|
message: error.message,
|
|
|
|
error,
|
2018-11-24 09:56:41 +09:00
|
|
|
details: { ...errorInfo, sourceVersion },
|
2018-11-04 16:32:34 +09:00
|
|
|
currentUser,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { error } = this.state;
|
|
|
|
return error ? (
|
|
|
|
<div className="error-catcher">
|
|
|
|
<Components.Flash message={{ id: 'errors.generic_report', properties: { errorMessage: error.message } }} />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
this.props.children
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
registerComponent('ErrorCatcher', ErrorCatcher, withCurrentUser);
|