B2B-88: add starter kit structure and elements
This commit is contained in:
14
packages/next/src/utils/index.ts
Normal file
14
packages/next/src/utils/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const zodParseFactory =
|
||||
<T extends z.ZodTypeAny>(schema: T) =>
|
||||
(data: unknown): z.infer<T> => {
|
||||
try {
|
||||
return schema.parse(data) as unknown;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
// handle error
|
||||
throw new Error(`Invalid data: ${err as string}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user