Files
open-saas/template/app/src/server/validation.ts
Franjo Mindek 3f463fb202 format
2025-09-18 11:42:49 +02:00

18 lines
486 B
TypeScript

import { HttpError } from "wasp/server";
import * as z from "zod";
export function ensureArgsSchemaOrThrowHttpError<Schema extends z.ZodType>(
schema: Schema,
rawArgs: unknown,
): z.infer<Schema> {
const parseResult = schema.safeParse(rawArgs);
if (!parseResult.success) {
console.error(parseResult.error);
throw new HttpError(400, "Operation arguments validation failed", {
errors: parseResult.error.errors,
});
} else {
return parseResult.data;
}
}