
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
@wthek/zod-express-interceptor
Advanced tools
Express middleware interceptor that transforms Zod validation errors into http-error-kit formatted errors.
http-error-kit
Seamlessly intercept and transform Zod validation errors in Express using http-error-kit
— no clutter, just clean error handling
Built for Express projects using http-error-kit
, this interceptor captures Zod validation errors and converts them into structured HttpError.BadRequest responses.
💡 What the HEK?! Still manually catching Zod errors in every route? Let
@wthek/zod-express-interceptor
intercept them globally and standardize your error flow.
HttpError.BadRequest
@wthek/express-middleware
details
@wthek/*-middleware
extensionnpm install @wthek/zod-express-interceptor
Add Middleware Just Before defining Routes
Use KitZodExpressInterceptor
after your route definitions, but before the final error-handling middleware like @wthek/express-middleware
.
This ensures Zod validation errors are transformed into http-error-kit
errors early, allowing WTHek or any other middlewares to handle them cleanly.
If the interceptor is placed before your routes, it won't catch the Zod errors since those are thrown inside route execution — after middleware execution phase.
import express from 'express';
import { z } from 'zod';
import { KitZodExpressInterceptor } from '@wthek/zod-express-interceptor';
import { KitExpressMiddleware } from '@wthek/express-middleware';
const app = express();
app.use(express.json());
app.post('/user', (req, res) => {
const schema = z.object({
name: z.string(),
age: z.number().min(18),
});
const parsed = schema.parse(req.body); // Will throw if invalid
res.send({ status: 'ok', parsed });
});
// ✅ Place interceptor BEFORE your routes
app.use(KitZodExpressInterceptor());
// ✅ Global error handler (after routes)
app.use(KitExpressMiddleware());
app.listen(3000);
KitHttpErrorConfig
To define how your error responses look in production:
import { KitHttpErrorConfig } from "http-error-kit";
KitHttpErrorConfig.configureFormatter(
(statusCode, message, details, ...args) => ({
code: statusCode,
msg: message,
extra: details,
traceId: args[0] || "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a",
})
);
// Response
{
"code": 400,
"msg": "Zod validation failed",
"extra": {
"issues": [
{
"code": "too_small",
"minimum": 18,
"type": "number",
"inclusive": true,
"exact": false,
"message": "Number must be greater than or equal to 18",
"path": ["age"]
}
]
},
"traceId": "0fcb44cb-4f09-4900-8c4f-73ddd37ffe0a"
}
The WTHek ecosystem continues to grow with new extensions to simplify error handling across various frameworks and libraries. Stay updated with the latest tools that integrate seamlessly with http-error-kit
.
Check out the official list of extensions: Official Extensions List
The original author of the project is Himanshu Bansal
This is all voluntary work, so if you want to support my efforts you can
You can also use the following:
@wthek/zod-express-interceptor
project is open-sourced software licensed under the MIT license by Himanshu Bansal.
FAQs
Express middleware interceptor that transforms Zod validation errors into http-error-kit formatted errors.
The npm package @wthek/zod-express-interceptor receives a total of 3 weekly downloads. As such, @wthek/zod-express-interceptor popularity was classified as not popular.
We found that @wthek/zod-express-interceptor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.