Skip to content
This repository has been archived by the owner on Aug 21, 2022. It is now read-only.

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

Open
LinusU opened this issue Aug 29, 2018 · 1 comment
Open

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

LinusU opened this issue Aug 29, 2018 · 1 comment

Comments

@LinusU
Copy link
Member

LinusU commented Aug 29, 2018

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
Copy link

max8hine commented Feb 2, 2019

those 2 libraries work like a charm!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants