We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2b3195c commit 2a64914Copy full SHA for 2a64914
template/app/src/server/validation.ts
@@ -0,0 +1,15 @@
1
+import { HttpError } from 'wasp/server';
2
+import * as z from 'zod';
3
+
4
+export function ensureArgsSchemaOrThrowHttpError<Schema extends z.ZodType>(
5
+ schema: Schema,
6
+ rawArgs: unknown
7
+): z.infer<Schema> {
8
+ const parseResult = schema.safeParse(rawArgs);
9
+ if (!parseResult.success) {
10
+ console.error(parseResult.error);
11
+ throw new HttpError(400, 'Operation arguments validation failed', { errors: parseResult.error.errors });
12
+ } else {
13
+ return parseResult.data;
14
+ }
15
+}
0 commit comments