Remove callApi, refactor API integrations, and adjust error handling
- Delete unused `callApi` utility and related imports across components. - Replace `callApi` with direct `fetch` usage in `validateCustomer` and `addCustomer`. - Update `customerRoutes` to include `/api` prefix for consistency. - Refactor `useErrorHandler` to ensure comprehensive state management during errors. - Improve `ErrorBoundary` component text for better clarity in fallback UI. - Align `CustomersPage` logic with `useCallback` for optimized dependency management.
This commit is contained in:
@@ -99,9 +99,9 @@ function ErrorDialog({error, onReset, open}: ErrorDialogProps) {
|
||||
}}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Ein Fehler ist aufgetreten</DialogTitle>
|
||||
<DialogTitle>Uncaught Error!</DialogTitle>
|
||||
<DialogDescription>
|
||||
Es ist ein unerwarteter Fehler aufgetreten. Bitte versuchen Sie es erneut.
|
||||
Es ist ein unerwarteter Fehler aufgetreten.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
@@ -128,7 +128,16 @@ function ErrorDialog({error, onReset, open}: ErrorDialogProps) {
|
||||
|
||||
// Hook for handling async errors
|
||||
export function useErrorHandler() {
|
||||
const [errorState, setErrorState] = React.useState();
|
||||
|
||||
console.log('Current state:', errorState);
|
||||
|
||||
return React.useCallback((error: unknown) => {
|
||||
console.error("Async error caught:", error);
|
||||
|
||||
// Trigger a re-render that will throw the error and be caught by the error boundary
|
||||
setErrorState(() => {
|
||||
throw error instanceof Error ? error : new Error(String(error));
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user