ErrorBoundary追加: アプリ全体のエラーハンドリング強化
- ErrorBoundaryコンポーネントを新規作成(App全体・ページ個別の二重ガード) - ImportPage: 日付フィールドのundefined時にlocaleCompareが落ちる問題を修正 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+8
-3
@@ -6,6 +6,7 @@ import JournalPage from './components/JournalPage';
|
|||||||
import LedgerPage from './components/LedgerPage';
|
import LedgerPage from './components/LedgerPage';
|
||||||
import BalanceSheetPage from './components/BalanceSheetPage';
|
import BalanceSheetPage from './components/BalanceSheetPage';
|
||||||
import SettingsPage from './components/SettingsPage';
|
import SettingsPage from './components/SettingsPage';
|
||||||
|
import { ErrorBoundary } from './components/ErrorBoundary';
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { currentPage } = useStore();
|
const { currentPage } = useStore();
|
||||||
@@ -22,8 +23,12 @@ export default function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<ErrorBoundary>
|
||||||
{renderPage()}
|
<Layout>
|
||||||
</Layout>
|
<ErrorBoundary>
|
||||||
|
{renderPage()}
|
||||||
|
</ErrorBoundary>
|
||||||
|
</Layout>
|
||||||
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
hasError: boolean;
|
||||||
|
error?: Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ErrorBoundary extends Component<Props, State> {
|
||||||
|
constructor(props: Props) {
|
||||||
|
super(props);
|
||||||
|
this.state = { hasError: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromError(error: Error): State {
|
||||||
|
return { hasError: true, error };
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidCatch(error: Error, info: ErrorInfo) {
|
||||||
|
console.error('[ErrorBoundary] Caught error:', error, info.componentStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.state.hasError) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center justify-center h-screen text-slate-400 p-8 bg-slate-900">
|
||||||
|
<p className="text-5xl mb-4">⚠️</p>
|
||||||
|
<p className="text-lg font-semibold text-slate-300 mb-2">エラーが発生しました</p>
|
||||||
|
<p className="text-sm text-slate-500 mb-6 max-w-md text-center break-all">
|
||||||
|
{this.state.error?.message}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={() => this.setState({ hasError: false })}
|
||||||
|
className="px-4 py-2 bg-indigo-600 text-white rounded-md text-sm hover:bg-indigo-700"
|
||||||
|
>
|
||||||
|
再試行
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,7 +78,7 @@ export default function ImportPage() {
|
|||||||
|
|
||||||
// 振替としてスキップされた取引(振替=1 のrawRecords)
|
// 振替としてスキップされた取引(振替=1 のrawRecords)
|
||||||
const skippedTransfers = useMemo(() =>
|
const skippedTransfers = useMemo(() =>
|
||||||
rawRecords.filter(r => r.振替 === '1' && r.ID).sort((a, b) => b.日付.localeCompare(a.日付)),
|
rawRecords.filter(r => r.振替 === '1' && r.ID).sort((a, b) => (b.日付 ?? '').localeCompare(a.日付 ?? '')),
|
||||||
[rawRecords]
|
[rawRecords]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user