feat(service): CardService générique sur l'abstraction CardRepository
This commit is contained in:
1 parent
a3d9be86d8
commit
12670b7134
3 files changed
+83
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { NextResponse, type NextRequest } from 'next/server'
|
||||
import { ZodError } from 'zod'
|
||||
import { AppError, ValidationError } from '@/domain/errors'
|
||||
|
||||
export function handleError(error: unknown): NextResponse {
|
||||
if (error instanceof ZodError) {
|
||||
return NextResponse.json(
|
||||
{ error: 'ValidationError', message: 'Payload invalide', issues: error.flatten() },
|
||||
{ status: 400 },
|
||||
)
|
||||
}
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json({ error: error.name, message: error.message }, { status: error.status })
|
||||
}
|
||||
console.error(error)
|
||||
return NextResponse.json({ error: 'InternalServerError', message: 'Erreur interne' }, { status: 500 })
|
||||
}
|
||||
|
||||
export async function parseJsonBody(request: NextRequest): Promise<unknown> {
|
||||
try {
|
||||
return await request.json()
|
||||
} catch {
|
||||
throw new ValidationError('Corps de requête invalide (JSON attendu)')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user