feat: implement error handling and validation middleware, enhance result handling
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
29
apps/backend/src/lib/http/problem-builders.ts
Normal file
29
apps/backend/src/lib/http/problem-builders.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
// http/problem-builders.ts
|
||||
import type { ProblemDetails } from './problem-details'
|
||||
|
||||
export function validationProblem(params: {
|
||||
detail?: string
|
||||
instance?: string
|
||||
errors?: Record<string, string[]>
|
||||
}): ProblemDetails {
|
||||
return {
|
||||
type: 'https://api.myapp.dev/problems/validation',
|
||||
title: 'Bad Request',
|
||||
status: 400,
|
||||
detail: params.detail ?? 'Invalid request data',
|
||||
instance: params.instance,
|
||||
errors: params.errors
|
||||
}
|
||||
}
|
||||
|
||||
export function unexpectedProblem(params?: {
|
||||
instance?: string
|
||||
}): ProblemDetails {
|
||||
return {
|
||||
type: 'https://api.myapp.dev/problems/unexpected',
|
||||
title: 'Internal Server Error',
|
||||
status: 500,
|
||||
detail: 'Internal server error',
|
||||
instance: params?.instance
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user