holidayextras / jsonapi-server

A config driven NodeJS framework implementing json:api and GraphQL
MIT License
488 stars 115 forks source link

Adding a route/handler for a different format #318

Open aledalgrande opened 7 years ago

aledalgrande commented 7 years ago

Hi, the project uses the JSON-API format for most of the logic, but there are some exceptions, like a downloadable CSV format of certain resources. How would I handle this in jsonapi-server? When I add a router to the Express app I got from jsonApi, it doesn't work. Also I get only this error, which is not helpful:

{"status":"500","code":"EUNKNOWN","title":"An unknown error has occured. Sorry?","detail":"??"}

Does this library swallow the errors of custom routes?

aledalgrande commented 7 years ago

The route worked, problem is the generic error handler of this library was set for Express, so I thought it was going through the default JSON API route. Commenting out the error handler in the library gave me access to the real error.

I guess it would be nice to be able to override the JSON API error handler or fire it only when the headers are right.

aledalgrande commented 7 years ago

Keeping it open to keep track of the feature request.

aledalgrande commented 7 years ago

This is also swallowing connection errors from the related jsonapi-store-relationaldb package. Errors could be easily shown with a log/inspect line in responseHelper.generateError, but in the debug prints you can only see a {}.