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

Bugfix: p.h.HTTPException.__str __ #2951

Merged
merged 3 commits into from
Feb 10, 2017
Merged

Conversation

digitalresistor
Copy link
Member

There are those crazies among us* that use something like the following:

raise HTTPBadRequest({'error': 'Invalid something or other'})

This blew up when attempting to call str() on the resulting object due to __str__ returning self.detail directly.

This fixes this and lets those crazies continue on with their craziness.

  • Me, I am that crazy person, because it makes things like this simple:
@view_config(
    accept='application/json',
    renderer='json',
    context=HTTPException,
    )
def reterror(context, request):
    try:
        if not context.detail:
            raise ValueError('Missing detail in context')
        context.json_body = context.detail
    except:
        context.json_body = {'error': 'Unknown error has occured.'}

    return context

@digitalresistor digitalresistor merged commit 40d71e8 into master Feb 10, 2017
@digitalresistor digitalresistor deleted the bugfix/httpexception__str__ branch February 10, 2017 01:13
digitalresistor added a commit that referenced this pull request Feb 10, 2017
(BP 1.8) Bugfix: httpexception  __str__

Backport of #2951
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