Skip to content

Commit

Permalink
fix: catch erreur in useValidatedParams
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes authored Jul 15, 2023
1 parent 40cc672 commit dc1524b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,16 @@ export async function useSafeValidatedBody<T extends Schema | z.ZodRawShape>(
* @param event - A H3 event object.
* @param schema - A Zod object shape or object schema to validate.
*/
export function useValidatedParams<T extends Schema | z.ZodRawShape>(
export async function useValidatedParams<T extends Schema | z.ZodRawShape>(
event: H3Event,
schema: T,
parseOptions?: ParseOptions,
): Promise<ParsedData<T>> {
try {
const params = getRouterParams(event)
const finalSchema = schema instanceof z.ZodType ? schema : z.object(schema)
return finalSchema.parseAsync(params, parseOptions)
const parsed = await finalSchema.parseAsync(params, parseOptions)
return parsed
}
catch (error) {
throw createBadRequest(error)
Expand Down

0 comments on commit dc1524b

Please sign in to comment.