Skip to content

Commit

Permalink
Merge pull request #649 from cynicaloptimist/development
Browse files Browse the repository at this point in the history
3.11.5 better error handling
  • Loading branch information
cynicaloptimist authored Sep 3, 2024
2 parents 48d138c + f9190a2 commit 951ef9a
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 449 deletions.
45 changes: 45 additions & 0 deletions client/Components/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as React from "react";

interface ErrorBoundaryProps {
children: React.ReactNode;
renderError: (error: Error, errorInfo: React.ErrorInfo) => React.ReactNode;
}

interface ErrorBoundaryState {
hasError: boolean;
error: Error | null;
errorInfo: React.ErrorInfo | null;
}

class ErrorBoundary extends React.Component<
ErrorBoundaryProps,
ErrorBoundaryState
> {
state: ErrorBoundaryState = {
hasError: false,
error: null,
errorInfo: null
};

constructor(props: ErrorBoundaryProps) {
super(props);
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
this.setState({
hasError: true,
error: error,
errorInfo: errorInfo
});
}

render() {
if (this.state.hasError) {
return this.props.renderError(this.state.error, this.state.errorInfo);
}

return this.props.children;
}
}

export default ErrorBoundary;
Loading

0 comments on commit 951ef9a

Please sign in to comment.