Skip to content

Commit

Permalink
fix: Properly wrap components in traditional HoC pattern (#13605)
Browse files Browse the repository at this point in the history
  • Loading branch information
dashed authored Jun 10, 2019
1 parent 13af8f5 commit ddbd59a
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/sentry/static/sentry/app/utils/errorHandler.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ import React from 'react';
import RouteError from 'app/views/routeError';

export default function errorHandler(Component) {
const originalRender = Component.prototype.render;
Component.prototype.render = function() {
try {
return originalRender.apply(this, arguments);
} catch (err) {
/*eslint no-console:0*/
class ErrorHandler extends React.Component {
static getDerivedStateFromError(error) {
setTimeout(() => {
throw err;
throw error;
});
return <RouteError error={err} component={this} />;

// Update state so the next render will show the fallback UI.
return {
hasError: true,
error,
};
}

state = {
hasError: false,
error: null,
};

render() {
if (this.state.hasError) {
return <RouteError error={this.state.error} />;
}

return <Component {...this.props} />;
}
};
return Component;
}

return ErrorHandler;
}

0 comments on commit ddbd59a

Please sign in to comment.