Express
Install Kilpi for Express
Ensure you have setup Kilpi using the quickstart guide before proceeding.
Installing Kilpi for Express is as easy as providing Kilpi scope within a middleware. You do not need any plugins.
app.use((req, res, next) => { Kilpi.runInScope(async () => { next(); });})
To handle unauthorized errors in Express, we recommend the following approach with a global error handler after all route definitions.
app.use((err, req, res, next) => { if (err instanceof KilpiError.AuthorizationDenied) { return res.status(403).json({ error: err.message }); }
// Handle other errors});