nationalparkservice / places-api

An API, written in Node as Express middleware, built to work with the OSM API database schema. Used internally by Places.
The Unlicense
0 stars 0 forks source link

Bug in error handling #9

Closed regan-sarwas closed 8 years ago

regan-sarwas commented 9 years ago

calling /api/0.6/bug, or any other 'bad' request throws: TypeError: Converting circular structure to JSON<br> &nbsp; &nbsp;at Object.stringify..... I'm not on the network, so I can't test with the production build.

The following is what I think is happening: in index.js you add a function to express https://github.com/nationalparkservice/places-api/blob/d8afcd3d18143f1da000912e945305f0747409bd/index.js#L38

The function should have a parameter set like (req,res,next) (see http://expressjs.com/4x/api.html#router.use)

in apiWrapper.js, the function is defined here

https://github.com/nationalparkservice/places-api/blob/d8afcd3d18143f1da000912e945305f0747409bd/src/apiWrapper.js#L292

and then here

https://github.com/nationalparkservice/places-api/blob/d8afcd3d18143f1da000912e945305f0747409bd/src/apiWrapper.js#L249

The first parameter is assumed to be an error object, not a request.

When this function is called by express, err is a express.Request, not an Error, and the following line throws the ugly error in the browser

https://github.com/nationalparkservice/places-api/blob/d8afcd3d18143f1da000912e945305f0747409bd/src/apiWrapper.js#L256

regan-sarwas commented 8 years ago

Fixed with commit e021435ddd2a448aea9b8fe7a7170a566acec935