| import { NextResponse } from 'next/server' |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| export function apiSuccess<T extends Record<string, unknown>>( |
| data: T, |
| status = 200 |
| ): NextResponse { |
| return NextResponse.json({ ok: true, ...data }, { status }) |
| } |
|
|
| export function apiError( |
| error: string, |
| status = 500, |
| extra?: Record<string, unknown> |
| ): NextResponse { |
| return NextResponse.json({ ok: false, error, ...extra }, { status }) |
| } |
|
|
| |
| export const ApiErrors = { |
| noApiBase: () => |
| apiError('API URL yapılandırılmamış. NEXT_PUBLIC_API_URL tanımlayın.', 500), |
|
|
| invalidJson: () => apiError('Geçersiz JSON body', 400), |
|
|
| bodyRequired: () => apiError('JSON body gerekli', 400), |
|
|
| invalidSymbol: () => |
| apiError('Geçerli bir symbol alanı gerekli (ör: THYAO)', 400), |
|
|
| upstream: (route: string, status: number, detail?: unknown) => |
| apiError(`Upstream ${route} error: ${status}`, status >= 400 ? status : 502, { |
| detail: detail ?? null, |
| }), |
|
|
| timeout: (route: string) => |
| apiError(`${route} isteği zaman aşımına uğradı`, 504), |
|
|
| unknown: (msg?: string) => |
| apiError(msg || 'Bilinmeyen hata', 502), |
| } as const |
|
|