api-error-handler
api-error-handler copied to clipboard
Best way to expose additional properties from http-errors
Trying to figure out how to best expose additional properties added to errors thru the http-errors package. Basically, what I'm trying to do is something like this:
const express = require('express')
const createError = require('http-errors')
const errorHandler = require('api-error-handler')
const app = express()
app.get('/test', function (req, res, next) {
next(createError(400, { foobar: 10 }))
})
app.use(errorHandler())
I don't think it's explicitly stated, but I think that these two packages are made to work together.
Would be happy with any input, maybe I'm missing something simple.
One way would be to add an option (exposeAdditionalProperties maybe) that simply iterates and sets the properties. I'd be happy to send a PR!
those 2 libraries work like a charm!