Skip to content

Commit 0156b80

Browse files
committed
chore: more readable validation error
1 parent bd53ef7 commit 0156b80

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

apps/backend/src/helpers/arktype.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { validator as arktypeValidator } from 'hono-openapi'
44
type arktypeValidatorArguments = Parameters<typeof arktypeValidator>
55
export function customArktypeValidator<Target extends arktypeValidatorArguments[0], Schema extends arktypeValidatorArguments[1]>(target: Target, schema: Schema) {
66
return arktypeValidator(target, schema, (result) => {
7-
if (result.success === false)
8-
throw new DetailedError('Validation failed', { statusCode: 400, detail: JSON.stringify(result.error) })
7+
if (result.success === false) {
8+
throw new DetailedError('Validation failed', {
9+
statusCode: 400,
10+
// Normalizes ArkErrors
11+
detail: JSON.parse(JSON.stringify(result.error)),
12+
})
13+
}
914
})
1015
}

0 commit comments

Comments
 (0)