Summary
Error handling
This release includes a small breaking change:
Prior to this release, if an error occurred in the Handler, it would throw an Error object. In this release, the error response is assigned to c.res
without throwing Error.
app.use('*', async (c, next) => {
await next()
// c.res is error reponse
})
app.get('/error', () => {
throw new Error('Test error')
})
Then you can access the original Error object with c.error
.
app.use('*', async (c, next) => {
await next()
const originalMessage = c.error.message
//...
})
For more information, See: #576
JSON array path validation
This is a pretty new feature. Support for array paths in JSON Path for use with Validator Middleware.
If there is a JSON request body as follows:
{
"posts": [
{
"title": "Good Morning",
"tags": ["Bar", true]
},
{
"title": "Good Night",
"tags": ["Bar", false]
}
]
}
We can validate with the following rules:
app.post(
'/posts',
validator((v) => ({
title: v.json('posts[*].title').asArray().isRequired(),
secondTag: v.json('posts[*].tags[1]').asArray().asBoolean(),
})),
(c) => {
return c.text('Valid')
}
)
Bug fixes
And some bug fixes.
What's Changed
- feat(validator): add support for JSON array path validation by @ThatOneBro in #563
- Fix Trie router multiple matching path parameters by @gatesn in #571
- refactor(bun/serve-static): don't check
c.res
by @yusukebe in #572 - fix(cache): export cache middleware for Deno by @ThatOneBro in #573
- fix(compose): don't throw Error; set error response into
c.res
by @yusukebe in #576 - fix(reg-exp-router): Register path for all the methods if method === METHOD_NAME_ALL. by @usualoma in #580
- fix(validator): return HTTP 400 on malformed JSON request by @ThatOneBro in #579
New Contributors
- @ThatOneBro made their first contribution in #563
- @gatesn made their first contribution in #571
Full Changelog: v2.2.3...v2.2.4