
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@elunic/express-error-handler
Advanced tools
A simple, minimalistic error handler middleware for Express
A simple, minimalistic error handler middleware for Express.
Support http-errors and has very partial support for some errors from common-errors.
Using this error handler will output nicely formatted JSON describing the type of error that occured and, optionally, the stack and error message.
If the handled error is an error from the http-errors module, or has a statusCode property,
the status code (and, for http-errors, the correct type) will be included:
const httpErrors = require('http-errors');
app.get('/errorGet', (req, res) => {
throw new httpErrors.NotFound('File not found');
})
Response body:
// STATUS CODE: 404
{
error: {
type: 'NotFoundError',
message: 'File not found',
stack: '<stack>'
}
}
$ npm install @elunic/express-error-handler
Example:
const app = require('express')();
const errorHandler = require('@elunic/express-error-handler')();
app.get('/get', (req, res) => {
// ...
});
// ... further route handlers ...
// Use AFTER all routes/other middlewares whose errors you wish to handle.
// Routes/middlewares added after this point will not have their errors handled.
app.use(errorHandler);
app.listen(80);
Example with full stack output (absolutely not recommended for production!):
const errorHandler = require('@elunic/express-error-handler')({
full: true,
});
Example callback:
const errorHandler = require('@elunic/express-error-handler')({
onError: (err) => {
console.error('Express stack error', err);
}
});
(The MIT License)
Copyright (c) 2018 elunic <wh@elunic.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
A simple, minimalistic error handler middleware for Express
We found that @elunic/express-error-handler demonstrated a not healthy version release cadence and project activity because the last version was released 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
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.