koa-zod-router
Advanced tools
Comparing version 2.0.0-beta.1 to 2.0.0
# koa-zod-router | ||
## 2.0.0 | ||
### Major Changes | ||
- 62874b1: Improved Router context by extending Koa.Context (Potential breaking change) | ||
Previously, koa-zod-router's context did not extend Koa.Context due to potential conflicts with other third-party libraries that may have overridden Koa.Context globally. However, after addressing all internal issues, we have now enhanced Router context by extending Koa.Context for better interoperability with other Koa-based libraries. | ||
While we have conducted thorough testing, there is still a possibility that this change may affect some third-party libraries. Hence, we are flagging this as a potential breaking change. | ||
Added feature: validationErrorHandler option for router-wide error handling | ||
## 1.2.1 | ||
@@ -4,0 +16,0 @@ |
{ | ||
"name": "koa-zod-router", | ||
"version": "2.0.0-beta.1", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -267,4 +267,29 @@ # ⚡ koa-zod-router ⚡ | ||
### Custom Validation Error Handling | ||
## Custom Validation Error Handling | ||
`koa-zod-router` allows users to implement router-wide error handling or route specific error handling. | ||
### Router-wide error handling | ||
By passing a function `validationErrorHandler` into `zodRouter` options you can execute an error handler that occurs immediately after the validation-middleware does it's thing. | ||
```js | ||
import { ValidationErrorHandler } from 'koa-zod-router'; | ||
const validationErrorHandler: ValidationErrorHandler = async (ctx, next) => { | ||
if (ctx.invalid.error) { | ||
ctx.status = 400; | ||
ctx.body = 'hello'; | ||
} else { | ||
await next(); | ||
} | ||
return; | ||
}; | ||
const router = zodRouter({ | ||
zodRouter: { exposeResponseErrors: true, validationErrorHandler }, | ||
}); | ||
``` | ||
### Route specific error handling | ||
By enabling `continueOnError` you can bypass the default error handling done by the router's validation middleware and handle the errors the way you see fit. | ||
@@ -271,0 +296,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
56861
1
346