-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
res.jsonx() now ensures that Error instances passed in end up with bo…
…th a .stack and .message property.
- Loading branch information
1 parent
2f4a008
commit b8c3813
Showing
1 changed file
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b8c3813
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future reference: This was completed as originally intended in e89078d by @fernandolguevara. Now other properties besides message+stack are maintained.
However, toJSON() is not run, so any errors with a custom toJSON method do not get serialized as expected. Most of the time, this doesn't matter, since most folks don't even know you can do this. But for people who do, this feels like unexpected behavior.
See also #3462.
Re: the original problem (validation error messages from Waterline being put in a state where they can't be parsed programmatically), this is mostly fixed-- but the set of exposed information contains more information than it used to:
Haven't looked into this much yet, but I believe it's because of the lack of
.toJSON()
-ing. Will link from here when I have more info.b8c3813
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the error data doesn't make it back to the client in production by default, this isn't any immediate problem, and so in order to maintain backwards compatibility, I'll leave it as-is. That said, be warned: In Sails v1.0, the implementation of error handling in blueprints will change, insofar as the default implementation of
api/responses/badRequest.js
will not protect the data you send through in production. This is to allowres.badRequest()
to absorb support for more of the customizations that normally result in just hand-rolling responses currently. Same thing for the default implementation ofres.forbidden()
andres.notFound()
.res.serverError()
will work exactly like it does now as far as preventing any error information from touching the response in production.The error marshaling in the responses hook in Sails core will also be pulled into the responses. This makes it easier to customize, particularly when it comes to stuff like
toJSON()
. The default implementations of res.forbidden() and res.notFound() will not return any information to the client at all. The default implementation of res.badRequest() will send through the provided request data verbatim. And res.serverError() will work the way it does today.