Skip to content

Commit

Permalink
feat(validation): improve validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Dec 7, 2023
1 parent afc4183 commit a71aadc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utils/internal/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export async function validateData<T>(
function createValidationError(validateError?: any) {
throw createError({
status: 400,
message: validateError.message || "Validation Failed",
...validateError,
statusMessage: "Bad Request",
message: validateError.message || "Bad Request",
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 a71aadc

Please sign in to comment.