Skip to content

Commit

Permalink
feat(validate): provide validate error in data (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Dec 7, 2023
1 parent afc4183 commit 18b8ec1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/utils/internal/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export async function validateData<T>(
function createValidationError(validateError?: any) {
throw createError({
status: 400,
message: validateError.message || "Validation Failed",
...validateError,
statusMessage: "Validation Error",
message: validateError?.message || "Validation Error",
data: validateError,
});
}
1 change: 1 addition & 0 deletions test/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe("Validate", () => {
it("Invalid", async () => {
const res = await request.post("/zod").send({ invalid: true });
expect(res.status).toEqual(400);
expect(res.body.data?.issues?.[0]?.code).toEqual("invalid_type");
});
});
});
Expand Down

0 comments on commit 18b8ec1

Please sign in to comment.