PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.11
Yatra – Travel Booking & Tour Operator Software v3.0.11
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / resources / js / components / ErrorBoundary.tsx

ErrorBoundary.tsx in Yatra – Travel Booking & Tour Operator Software 3.0.11, at resources/js/components/ErrorBoundary.tsx

75 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * App-level error boundary.
3 *
4 * Catches render/commit-phase exceptions (including DOM reconciliation errors
5 * such as "Failed to execute 'removeChild' on 'Node'", which browser
6 * auto-translation can trigger by mutating React-managed text nodes) so a
7 * single subtree failure degrades to a friendly reload prompt instead of an
8 * uncaught exception that white-screens the admin.
9 */
10
11 import React from "react";
12 import { __ } from "../lib/i18n";
13
14 interface ErrorBoundaryProps {
15 children: React.ReactNode;
16 }
17
18 interface ErrorBoundaryState {
19 hasError: boolean;
20 }
21
22 export class ErrorBoundary extends React.Component<
23 ErrorBoundaryProps,
24 ErrorBoundaryState
25 > {
26 constructor(props: ErrorBoundaryProps) {
27 super(props);
28 this.state = { hasError: false };
29 }
30
31 static getDerivedStateFromError(): ErrorBoundaryState {
32 return { hasError: true };
33 }
34
35 componentDidCatch(error: unknown, info: unknown): void {
36 // Keep a console record for support/debugging; not shown to the user.
37 console.error("Yatra admin caught a rendering error:", error, info);
38 }
39
40 private handleReload = (): void => {
41 window.location.reload();
42 };
43
44 render(): React.ReactNode {
45 if (!this.state.hasError) {
46 return this.props.children;
47 }
48
49 return (
50 <div className="flex items-center justify-center min-h-[50vh] p-6">
51 <div className="max-w-md text-center">
52 <h2 className="text-xl font-semibold text-gray-900 dark:text-white mb-2">
53 {__("Something went wrong", "yatra")}
54 </h2>
55 <p className="text-sm text-gray-600 dark:text-gray-400 mb-5">
56 {__(
57 "The page hit an unexpected error and needs to reload. Your data is safe.",
58 "yatra",
59 )}
60 </p>
61 <button
62 type="button"
63 onClick={this.handleReload}
64 className="inline-flex items-center justify-center px-4 py-2 rounded-md bg-blue-600 text-white text-sm font-medium hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
65 >
66 {__("Reload page", "yatra")}
67 </button>
68 </div>
69 </div>
70 );
71 }
72 }
73
74 export default ErrorBoundary;
75