Skip to content

Allow Error Handler to Return HttpResponse #458

Open
@JavaScriptDude

Description

I would like to have full control of the response from error handlers assigned using @api.errorhandler decorator so I can obfuscate the return of calls for some usecases.

For example:

@app.errorhandler(werkzeug.exceptions.BadRequest)
def handle_bad_request(e):
    log.error("<error_dump>", error)
    response = flask.make_response()
    response.set_data(":(")
    response.status_code = 418
    response.headers['Content-Type'] = 'text/html'
    response.headers['Server'] = 'Timex Sinclair'
    return response

However, the code assumes full control of the response assuming that a dict is returned.

The change is quite simple. In Api.py after result = handler(e):

if not result is None and  issubclass(result.__class__, BaseResponse):
    return result

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions