🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

agnostic-http-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agnostic-http-error-handler

Node.js framework agnostic HTTP error handler

1.0.1
latest
Source
npm
Version published
Weekly downloads
75
-34.78%
Maintainers
1
Weekly downloads
 
Created
Source

agnostic-http-error-handler

Node.js framework agnostic HTTP error handler.

Usage

Express.js

const { express: errMiddleware } = require('agnostic-http-error-handler')()

const service = require('express')()
service.get('/throw', (req, res) => {
  throw new Error('Upps!')
})

service.use(errMiddleware)

service.listen(3000)

Restana

const { restana: errorHandler } = require('agnostic-http-error-handler')()
const service = require('restana')({
  errorHandler
})

service.get('/throw', (req, res) => {
  throw new Error('Upps!')
})

service.start()

Native

const { native: errorHandler } = require('agnostic-http-error-handler')()
...
server.on('request', (req, res) => {
  try {
    // request handler logic...
  } catch (err) {
    errorHandler(err, req, res)
  }
})

Pre-Error-Handler callback

In case you would like to extend the error processing logic of your application, you can use the preErrorHandler configuration callback:

const logger = require('...')
const { native: errorHandler } = require('agnostic-http-error-handler')((err, responsePayload, req, res) => {
  logger.error(`Unexpected error while processing "${req.method} ${req.url}" request`, err)
})

...
server.on('request', (req, res) => {
  try {
    // request handler logic...
  } catch (err) {
    errorHandler(err, req, res)
  }
})

NOTE: In case the preErrorHandler invocation response can be coerce as a TRUE value, sending the responsePayload to the client is aborted.

Sponsors

  • Kindly sponsored by ShareNow, a company that promotes innovation!

Keywords

HTTP

FAQs

Package last updated on 30 Mar 2020

Did you know?

Socket

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.

Install

Related posts