Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
express-default-errors
Advanced tools
Readme
Default ExpressJS error-handling middleware.
$ npm install express-default-errors
express-default-errors
provides simple middleware to catch default errors and serve custom errors.
var express = require('express')
var errorHandler = require('express-default-errors')
var app = express()
var router = express.Router()
// Valid route that will not cause any errors
router.get('/', function (req, res, next) {
res.status(200)
res.send('success')
})
// To signify unauthorized access, simple create a new Error object with status = 401
router.get('/restricted-route', function (req, res, next) {
var err = new Error()
err.status = 401
next(err)
})
// Custom error message
router.get('/error-route', function (req, res, next) {
// Will default to err.status = 500 unless err.status is explicitly set
var err = new Error('A custom error was caused.')
next(err)
})
// This is not recommended, but you could also set non-standard status codes.
// The default error message will be 'Internal Server Error' unless set.
router.get('/invalid-status-code-error-route', function (req, res, next) {
var err = new Error()
err.status = 299
next(err)
})
// Any errors will be sent with the appropriate status code by the response object as:
// {error: 'My error message here'}
// The error handler should be used after all routers
app.use(router)
app.use(errorHandler())
app.listen(3000)
Setting the status code will cause the middleware to serve default error messages when calling new Error()
without passing in any arguments, or if err.message
is not set.
Status Code | Default Message |
---|---|
400 | Bad Request |
401 | Unauthorized |
404 | Not Found |
500 | Internal Server Error |
MIT
FAQs
Default ExpressJS error-handling middleware.
The npm package express-default-errors receives a total of 3 weekly downloads. As such, express-default-errors popularity was classified as not popular.
We found that express-default-errors 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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.