middleware icon indicating copy to clipboard operation
middleware copied to clipboard

Make it possible to define a different HTTP Status Code without using…

Open Matzu89 opened this issue 2 years ago • 2 comments

… a hook

Hope you open to the following..

I usually return 422 on invalid data, would be nice to set this without writing out a hook on every request.

Matzu89 avatar Jan 28 '24 14:01 Matzu89

⚠️ No Changeset found

Latest commit: c4f7cd7c9d57cc24cb151d2a00da06c7e5731f58

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jan 28 '24 14:01 changeset-bot[bot]

Hi @Matzu89

Use a hook instead of it:

app.get(
  '/',
  zValidator('query', schema, (result, c) => {
    if (!result.success) {
      return c.json(result, 422)
    }
  }),
  (c) => {
    return c.json(0)
  }
)

yusukebe avatar Jan 28 '24 21:01 yusukebe