
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
express-error-handler
Advanced tools
A graceful error handler for Express applications.
var express = require('express'),
errorHandler = require('../error-handler.js'),
app = express(),
env = process.env,
port = env.myapp_port || 3000,
http = require('http'),
server;
// Route that triggers a sample error:
app.get('/error', function createError(req,
res, next) {
var err = new Error('Sample error');
err.status = 500;
next(err);
});
// Create the server object that we can pass
// in to the error handler:
server = http.createServer(app);
// Log the error
app.use(function (err, req, res, next) {
console.log(err);
next(err);
});
// Respond to errors and conditionally shut
// down the server. Pass in the server object
// so the error handler can shut it down
// gracefully:
app.use( errorHandler({server: server}) );
server.listen(port, function () {
console.log('Listening on port ' + port);
});
Here are the parameters you can pass into the errorHandler()
middleware:
@param {object} [options]
@param {object} [options.handlers] Custom handlers for specific status codes.
@param {object} [options.views] View files to render in response to specific status codes. Specify a default with options.views.default
@param {object} [options.static] Static files to send in response to specific status codes. Specify a default with options.static.default.
@param {number} [options.timeout] Delay between the graceful shutdown attempt and the forced shutdown timeout.
@param {number} [options.exitStatus] Custom process exit status code.
@param {object} [options.server] The app server object for graceful shutdowns.
@param {function} [options.shutdown] An alternative shutdown function if the graceful shutdown fails.
@param {function} serializer a function to customize the JSON error object. Usage: serializer(err) return errObj
@return {function} errorHandler Express error handling middleware.
See the tests for more examples.
Return true if the error status represents a client error that should not trigger a restart.
errorHandler.isClientError(404); // returns true
errorHandler.isClientError(500); // returns false
Take an error status and return a route that sends an error with the appropriate status and message to an error handler via next(err)
.
* // Define supported routes
* app.get( '/foo', handleFoo() );
* // 405 for unsupported methods.
* app.all( '/foo', createHandler.httpError(405) );
FAQs
A graceful error handler for Express applications.
The npm package express-error-handler receives a total of 1,103 weekly downloads. As such, express-error-handler popularity was classified as popular.
We found that 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.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.