feat: implement error handling and validation middleware, enhance result handling
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
18
apps/backend/src/lib/http/zod-issues.ts
Normal file
18
apps/backend/src/lib/http/zod-issues.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
type IssueLike = {
|
||||
path: PropertyKey[]
|
||||
message: string
|
||||
}
|
||||
|
||||
export function zodIssuesToRecord(
|
||||
issues: IssueLike[]
|
||||
): Record<string, string[]> {
|
||||
const out: Record<string, string[]> = {}
|
||||
|
||||
for (const issue of issues) {
|
||||
const key = issue.path.length ? issue.path.join('.') : 'root'
|
||||
out[key] ??= []
|
||||
out[key].push(issue.message)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user