Download src/lib/server/api-response.ts from muthuk1/OpenMAIC-React: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/muthuk1/OpenMAIC-React/resolve/f56a29bb577c3dbea4b71ec00b9720e408aa1469/src/lib/server/api-response.ts
- Command line
-
hf download hf://muthuk1/OpenMAIC-React@f56a29bb577c3dbea4b71ec00b9720e408aa1469/src/lib/server/api-response.ts
-
curl -L -o api-response.ts https://huggingface.co/muthuk1/OpenMAIC-React/resolve/f56a29bb577c3dbea4b71ec00b9720e408aa1469/src/lib/server/api-response.ts
1.29 kB
| import { NextResponse } from 'next/server'; | |
| export const API_ERROR_CODES = { | |
| MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD', | |
| MISSING_API_KEY: 'MISSING_API_KEY', | |
| INVALID_REQUEST: 'INVALID_REQUEST', | |
| VOXCPM_AUTO_VOICE_REQUIRES_CONTEXT: 'VOXCPM_AUTO_VOICE_REQUIRES_CONTEXT', | |
| INVALID_URL: 'INVALID_URL', | |
| REDIRECT_NOT_ALLOWED: 'REDIRECT_NOT_ALLOWED', | |
| CONTENT_SENSITIVE: 'CONTENT_SENSITIVE', | |
| UPSTREAM_ERROR: 'UPSTREAM_ERROR', | |
| GENERATION_FAILED: 'GENERATION_FAILED', | |
| TRANSCRIPTION_FAILED: 'TRANSCRIPTION_FAILED', | |
| PARSE_FAILED: 'PARSE_FAILED', | |
| INTERNAL_ERROR: 'INTERNAL_ERROR', | |
| } as const; | |
| export type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES]; | |
| export interface ApiErrorBody { | |
| success: false; | |
| errorCode: ApiErrorCode; | |
| error: string; | |
| details?: string; | |
| } | |
| export function apiError( | |
| code: ApiErrorCode, | |
| status: number, | |
| error: string, | |
| details?: string, | |
| ): NextResponse<ApiErrorBody> { | |
| return NextResponse.json( | |
| { | |
| success: false as const, | |
| errorCode: code, | |
| error, | |
| ...(details ? { details } : {}), | |
| }, | |
| { status }, | |
| ); | |
| } | |
| export function apiSuccess<T extends Record<string, unknown>>(data: T, status = 200): NextResponse { | |
| return NextResponse.json({ success: true, ...data }, { status }); | |
| } | |