expressjs / api-error-handler

Express error handlers for JSON APIs
MIT License
101 stars 23 forks source link

Best way to expose additional properties from http-errors #7

Open LinusU opened 6 years ago

LinusU commented 6 years ago

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!

max8hine commented 5 years ago

those 2 libraries work like a charm!