jsonify()
produces a full response object, not a response body, so use HTTPException.get_response()
, not .get_body()
:
class JSONException(HTTPException):
def get_response(self, environ):
return jsonify(a=1)
The alternative is to just use json.dumps()
to produce a body here:
class JSONException(HTTPException):
def get_body(self, environ):
return json.dumps({a: 1})
def get_headers(self, environ):
return [('Content-Type', 'application/json')]