feat: implement error handling and validation middleware, enhance result handling

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Jose Selesan
2026-04-23 16:35:57 -03:00
parent 7bfa3b390e
commit 20d6018836
14 changed files with 306 additions and 8 deletions

View File

@@ -0,0 +1,58 @@
// lib/errors.ts
export type ValidationIssue = {
path: string
message: string
}
export type AppError =
| {
type: 'validation'
message: string
issues?: ValidationIssue[]
}
| {
type: 'not_found'
message: string
}
| {
type: 'conflict'
message: string
}
| {
type: 'unauthorized'
message: string
}
| {
type: 'forbidden'
message: string
}
| {
type: 'unexpected'
message: string
}
export const Errors = {
validation(message: string, issues?: ValidationIssue[]): AppError {
return { type: 'validation', message, issues }
},
notFound(message = 'Resource not found'): AppError {
return { type: 'not_found', message }
},
conflict(message: string): AppError {
return { type: 'conflict', message }
},
unauthorized(message = 'Unauthorized'): AppError {
return { type: 'unauthorized', message }
},
forbidden(message = 'Forbidden'): AppError {
return { type: 'forbidden', message }
},
unexpected(message = 'Unexpected error'): AppError {
return { type: 'unexpected', message }
}
}