Comments (2)
@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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api-error-handler.