Download client/services/httpError.tsx from marvin-cusm-chatbot/champ-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/marvin-cusm-chatbot/champ-chatbot/resolve/main/client/services/httpError.tsx
- Command line
-
hf download hf://spaces/marvin-cusm-chatbot/champ-chatbot/client/services/httpError.tsx
-
curl -L -o httpError.tsx https://huggingface.co/spaces/marvin-cusm-chatbot/champ-chatbot/resolve/main/client/services/httpError.tsx
949 Bytes
| import type { TranslationKey } from "@/translations"; | |
| // A response that isn't ok. Anything else fetch throws is a network error. | |
| export class HttpError extends Error { | |
| status: number; | |
| constructor(status: number) { | |
| super(`HTTP ${status}`); | |
| this.name = "HttpError"; | |
| this.status = status; | |
| } | |
| } | |
| type AuthErrorKey = Extract<TranslationKey, "error_signed_out" | "error_email_not_verified">; | |
| // Said instead of any request's own failure message: the user has to act before anything works. | |
| export const authErrorKey = (status?: number): AuthErrorKey | undefined => { | |
| if (status === 401) return "error_signed_out"; | |
| if (status === 403) return "error_email_not_verified"; | |
| return undefined; | |
| }; | |
| export const requestErrorKey = <K extends TranslationKey>( | |
| err: unknown, | |
| serverKey: K, | |
| networkKey: K, | |
| ): K | AuthErrorKey => { | |
| if (!(err instanceof HttpError)) return networkKey; | |
| return authErrorKey(err.status) ?? serverKey; | |
| }; | |