Errors and feedback
Toasts, API error shapes, and network handling in ApiTables
Files: ./ApiTables/table-utils/errorHandling.ts, plus sonner toasts from ./ApiTables/table-utils/utils.tsx (clipboard).
Success and validation (handleResponseErrors)
Used after row and bulk POSTs (inside useUtilsProvider) when the response is normal JSON (not blob export).
| Response shape | UI |
|---|---|
data.success === true | Runs success callback; optional toast.success(message) |
data.message without success/errors | toast.error(message) |
data.errors as array | One toast per item |
data.errors as string | Single error toast |
data.errors as object | Toasts joined field errors |
| Failure without errors | Error callback only |
Backend teams should keep success, errors, and message consistent so the UI behaves predictably.
Network errors (handleNetworkErrors)
Used by useTableFetcher and action POST catch blocks.
| Case | Behavior |
|---|---|
| HTTP 401 | Calls internalAxios.delete("/api/delete-auth"); redirects to /login on success |
Cancelled request (ERR_CANCELED) | Silent return (in-flight fetch aborted) |
response.data.error string or array | Error toast(s) |
| Fallback | toast.error(err.message || "Something went wrong!") |
Aborted fetches in useTableFetcher leave loading true when cancelled (by design) so a replacement request can finish.
User-initiated copy
copyToClipboard in utils.tsx shows a success toast (default Arabic message "تم النسخ" unless overridden).
Global loader (not in errorHandling)
Bulk actions dispatch _setMainLoader on the app store during POST — see useUtilsProvider. That is separate from table-local loading flags.