mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-20 21:55:03 -04:00
d99a7e9b8a
(cherry picked from commit e1cbc4a78249881de96160739a50c0a399ea4313) Closes #10378 Fixed: Links tooltip closing too quickly (cherry picked from commit 0b9a212f33381d07ff67e2453753aaab64cc8041) Closes #10400 Fixed: Movie links not opening on iOS (cherry picked from commit f20ac9dc348e1f5ded635f12ab925d982b1b8957) Closes #10425
47 lines
983 B
TypeScript
47 lines
983 B
TypeScript
import * as sentry from '@sentry/browser';
|
|
import React, { Component, ErrorInfo } from 'react';
|
|
|
|
interface ErrorBoundaryProps {
|
|
children: React.ReactNode;
|
|
errorComponent: React.ElementType;
|
|
}
|
|
|
|
interface ErrorBoundaryState {
|
|
error: Error | null;
|
|
info: ErrorInfo | null;
|
|
}
|
|
|
|
// Class component until componentDidCatch is supported in functional components
|
|
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
constructor(props: ErrorBoundaryProps) {
|
|
super(props);
|
|
|
|
this.state = {
|
|
error: null,
|
|
info: null,
|
|
};
|
|
}
|
|
|
|
componentDidCatch(error: Error, info: ErrorInfo) {
|
|
this.setState({
|
|
error,
|
|
info,
|
|
});
|
|
|
|
sentry.captureException(error);
|
|
}
|
|
|
|
render() {
|
|
const { children, errorComponent: ErrorComponent } = this.props;
|
|
const { error, info } = this.state;
|
|
|
|
if (error) {
|
|
return <ErrorComponent error={error} info={info} />;
|
|
}
|
|
|
|
return children;
|
|
}
|
|
}
|
|
|
|
export default ErrorBoundary;
|