api-error-handler icon indicating copy to clipboard operation
api-error-handler copied to clipboard

Best way to expose additional properties from http-errors

Open LinusU opened this issue 7 years ago • 1 comments

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!

LinusU avatar Aug 29 '18 12:08 LinusU

those 2 libraries work like a charm!

max8hine avatar Feb 02 '19 05:02 max8hine