Giter Site home page Giter Site logo

Comments (2)

blakeembrey avatar blakeembrey commented on April 26, 2024

@max8hine What is body in this case? If you're just after logging the error, you can do:

app.use((err, req, res, next) => { 
  console.log(err)
  next(err)
})

from api-error-handler.

max8hine avatar max8hine commented on April 26, 2024

Please correct me if my case is a wrong use case.

body is what this middleware produce. I found in the index.js

I want to console log the formatted error object, and then some server providers will pick it up and transfer to the provider logs, such as Heroku.

This middleware also runs res.json() instead of next(), so it's kind of the end of a req/res. I've been using the middleware at the end of my APIs routes, just like the test.js does.

an example of my use case

const express = require('express')
const createError = require('http-errors')
const errorHandler = require('api-error-handler')

const app = express();

app.get('/', (req, res, next) => {
  try {
	throw new Error('A ERROR!!!')
  } catch (err) {
	next(createError(400, Error))
  }
})

app.use(errorHandler(
  // * just add a callback,
  // * that allow us do some background jobs
  function(body) {
	  // body is errorHandler provided
	  // task 1, console.log error
	  console.log(body, '🚨')
	  // Task 2, send a error notification email to admin
	  ...
  }
))

Hope the case makes sense here =)

from api-error-handler.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.