Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download web/app/utils/errors.ts from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/edb5ea459a6e19d91e941f078c1ff1799d310731/web/app/utils/errors.ts
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway@edb5ea459a6e19d91e941f078c1ff1799d310731/web/app/utils/errors.ts
-
curl -L -o errors.ts https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/edb5ea459a6e19d91e941f078c1ff1799d310731/web/app/utils/errors.ts
1.1 kB
| import Bag from './bag' | |
| import { capitalize } from './capitalize' | |
| import { toApiError } from './api-error' | |
| export class ErrorMessages extends Bag<string> {} | |
| const sanitize = (key: string, values: Array<string>): Array<string> => { | |
| return values.map((value: string) => { | |
| return capitalize( | |
| value | |
| .split(key) | |
| .join(key.replace('_', ' ')) | |
| .split('_') | |
| .join(' ') | |
| .split('-') | |
| .join(' ') | |
| .split(' char') | |
| .join(' character') | |
| .split(' field ') | |
| .join(' '), | |
| ) | |
| }) | |
| } | |
| export const getErrorMessages = (error: unknown): ErrorMessages => { | |
| const errors = new ErrorMessages() | |
| const apiError = toApiError(error) | |
| const response = 'response' in apiError ? toApiError(apiError.response) : {} | |
| const data = apiError.data?.data ?? response.data?.data | |
| const status = apiError.status ?? response.status | |
| if (typeof data !== 'object' || data === null || status !== 422) { | |
| return errors | |
| } | |
| Object.entries(data).forEach(([key, values]) => { | |
| errors.addMany(key, sanitize(key, values)) | |
| }) | |
| return errors | |
| } | |