Refactor error handling utilities
- Replace `showError` with a more versatile `showToast` utility. - Add specific toast functions (`showErrorToast`, `showSuccessToast`, etc.) for better message handling. - Remove `showError.ts` and migrate logic to `showToast.ts` for cleaner structure. - Update `ErrorBoundary` and `useErrorHandler` to use the new `showToast` functions.
This commit is contained in:
@@ -25,6 +25,7 @@ import {NewCustomerModal} from "@/components/customers/modal/NewCustomerModal";
|
||||
import {Customer} from "@/services/customers/entities/customer";
|
||||
import Link from "next/link";
|
||||
import {useErrorHandler} from "@/components/error-boundary";
|
||||
import {showError, showInfoToast} from "@/lib/ui/showToast";
|
||||
|
||||
export default function CustomersPage() {
|
||||
const [customers, setCustomers] = useState<Customer[]>([]);
|
||||
@@ -39,14 +40,17 @@ export default function CustomersPage() {
|
||||
fetch('/api/customers')
|
||||
.then(async (response) => {
|
||||
if (!response.ok) {
|
||||
showError("Failed to fetch customers data")
|
||||
throw new Error(`Failed to fetch customers: ${response.statusText}`);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
showInfoToast("Customers data loaded")
|
||||
setCustomers(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
showError("Failed to fetch customers data (1)")
|
||||
handleError(error);
|
||||
setCustomers([]);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user