Spaces:
Running
Running
Download src/utils/apiError.ts from its-seraj/auth-service: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/spaces/its-seraj/auth-service/resolve/main/src/utils/apiError.ts
- Command line
-
hf download hf://spaces/its-seraj/auth-service/src/utils/apiError.ts
-
curl -L -o apiError.ts https://huggingface.co/spaces/its-seraj/auth-service/resolve/main/src/utils/apiError.ts
1.38 kB
| export class ApiError extends Error { | |
| public readonly statusCode: number; | |
| public readonly isOperational: boolean; | |
| public readonly details?: unknown; | |
| constructor(statusCode: number, message: string, details?: unknown, isOperational = true) { | |
| super(message); | |
| this.statusCode = statusCode; | |
| this.isOperational = isOperational; | |
| this.details = details; | |
| Object.setPrototypeOf(this, new.target.prototype); | |
| Error.captureStackTrace(this, this.constructor); | |
| } | |
| static badRequest(message: string, details?: unknown): ApiError { | |
| return new ApiError(400, message, details); | |
| } | |
| static unauthorized(message = 'Unauthorized', details?: unknown): ApiError { | |
| return new ApiError(401, message, details); | |
| } | |
| static forbidden(message = 'Forbidden', details?: unknown): ApiError { | |
| return new ApiError(403, message, details); | |
| } | |
| static notFound(message = 'Resource not found', details?: unknown): ApiError { | |
| return new ApiError(404, message, details); | |
| } | |
| static conflict(message: string, details?: unknown): ApiError { | |
| return new ApiError(409, message, details); | |
| } | |
| static tooManyRequests(message = 'Too many requests, please try again later.'): ApiError { | |
| return new ApiError(429, message); | |
| } | |
| static internal(message = 'Internal server error'): ApiError { | |
| return new ApiError(500, message, undefined, false); | |
| } | |
| } | |