Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: JSON exceptions #2489

Merged
merged 14 commits into from
Apr 14, 2016
Merged

Feature: JSON exceptions #2489

merged 14 commits into from
Apr 14, 2016

Conversation

digitalresistor
Copy link
Member

This is to bring Pyramid in-line with the changes that were made to WebOb's exceptions and to allow for generation of JSON exceptions.

#2406

Accept doesn't understand the notation of major/minor masks.
The default is now text/plain, so explicitly set the accept header for
what we want to accept.
This simply makes sure we get back the appropriate Content-Type based
upon our Accept header.
We also test out the custom formatter that allows the user to change how
the JSON is formatted for the exception.
application/json however doesn't have a charset, so we just specify that
as UTF-8 for the purpose of encoding the bytes.
@digitalresistor digitalresistor added this to the 1.8 milestone Apr 13, 2016
This means that to make "text/plain" the default, we need to
specifically make it the first thing we offer.

For anything else, since the server offers are all weighted equally, the
client order should be accepted.
This matches the original code whereby it would return an HTML page if
you sent an Accept header of */*.
@digitalresistor
Copy link
Member Author

@mmerickel Take a look at this.

To understand why I was concerned WebOb was broken (and IMHO the ordering is wrong, but nobody but Apache implements it, and Apache implements it the same way as WebOb...) see this long issue: Pylons/webob#239

Either way, this is ready to be merged if you are happy with it.

@digitalresistor digitalresistor modified the milestones: 1.7, 1.8 Apr 14, 2016
@mmerickel
Copy link
Member

This looks great. Could you please add a changelog that mentions any possible incompatibilities?

@digitalresistor
Copy link
Member Author

Should be no incompatibilities. It now does the right thing when the client provides an Acccept of application/json and returns a JSON response.

I can add a CHANGELOG announcing the change.

@digitalresistor
Copy link
Member Author

I did match the signature for json_formatter to be the same as the one used by WebOb. This should allow users to easily move those between projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants