| 1 | import { toast } from "sonner"; |
| 2 | |
| 3 | async function handleError(status: number, response: Response): Promise<void> { |
| 4 | if (status >= 500) { |
| 5 | // TODO: show error toast |
| 6 | } else if (status === 401) { |
| 7 | // TODO: show error toast |
| 8 | } else if (status === 403) { |
| 9 | // TODO: show error toast |
| 10 | } else if (status === 400) { |
| 11 | const errors = (await response.json()) as ValidationError; |
| 12 | const message = Object.values(errors.errors).flat().join("\n"); |
| 13 | toast.error(message); |
| 14 | throw new Error(message); |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | const commonHeaders: RequestInit = { |
| 19 | credentials: "include", |