Core: Change exception format on --api-only

Created on 10 Dec 2019  路  2Comments  路  Source: adonisjs/core

Exception format it's pretty nice while where creating a fullstack app, the problem is when whe use Adonis for API development, the error it's kinda unreadable while using tools like Postman. It would be so much readable use the Acept header and return a format dynamic response.

Actually, make a simple handler with adonis make:ehandler with
async handle(error, {response}) { response.status(error.status).json({ message: error.message, error: error.name }) }
works pretty fine. But I think it would be a better developement experiencie just done this by default.

Let me hear in what I can help.

Question

Most helpful comment

Hey @MarcoMacedoP! 馃憢

Adonis is Content Negotiation to generate the response for this kind of thing.
If you are receiving HTML while sending a request using a tool like Postman it's because you send a bad request. Ensure to have the Accept header with application/json when you send your request.

If you are 100% sure to only have JSON output, you can create a middleware that force this header for any request.

All 2 comments

Hey @MarcoMacedoP! 馃憢

Adonis is Content Negotiation to generate the response for this kind of thing.
If you are receiving HTML while sending a request using a tool like Postman it's because you send a bad request. Ensure to have the Accept header with application/json when you send your request.

If you are 100% sure to only have JSON output, you can create a middleware that force this header for any request.

Closing since no response from the issue reporter and not actionable as well

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GianCastle picture GianCastle  路  3Comments

begueradj picture begueradj  路  3Comments

blendsoft picture blendsoft  路  3Comments

milosdakic picture milosdakic  路  3Comments

codingphasedotcom picture codingphasedotcom  路  3Comments