trails icon indicating copy to clipboard operation
trails copied to clipboard

Standard and custom responses

Open enten opened this issue 9 years ago • 4 comments

Do you plan to implement custom responses feature like in sails?

Or is there already exists a fast way to do that?

I think that it's a useful helper to manage standard responses like 404 errors (when a controller or a model was not found), 401 errors (when data sent to a model does not valid its schema), forbidden responses (403 errors) when a policy was not respect, etc.

enten avatar Feb 07 '16 20:02 enten

Off-topic: 401 should be used for unauthorized requests, not when a model's schema validation fails. See Wiki.

robertrossmann avatar Feb 07 '16 23:02 robertrossmann

Yes, I was wrong. The 400 error is more suitable.

But how about the feature? Do you know if there will be implemented (or something similar)?

enten avatar Feb 08 '16 06:02 enten

But how about the feature? Do you know if there will be implemented (or something similar)?

I haven't decided, honestly, if this is something that the webserver trailpacks should be forced to include. hapi can use boom to customize responses and errors. For express, you could include express-custom-responses. I want trails to be webserver-agnostic and also lightweight; since solutions exist for many popular webserver modules already, I'm hesitant to create a new trails-y abstraction for this.

I'm open to other ideas. If someone in the community wants to build a "trailpack-custom-responses" module, we would encourage that.

tjwebb avatar Feb 10 '16 17:02 tjwebb

Thanks for your answer. I'm agree with your opinion.

I'm hesitant to create a new trails-y abstraction for this.

Can you expand this idea? Your opinion may be helpful if the community starts to build a trailpack for this feature.

enten avatar Feb 10 '16 19:02 enten