Skip to content
Myr

Move JSONHTTPException and JSONBadRequest to new module flask.exceptions.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Anton I. Sipos · committed by Anton I. Sipos · parent 9711fd4 · Browse files · 2 files+50 added−38 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+50 added−38 removed

  • other:+50 added−38 removed

2 files+50 added−38 removed

added:flask/exceptions.py+49 added
1# -*- coding: utf-8 -*-2"""3 flask.exceptions4 ~~~~~~~~~~~~56 Flask specific additions to :class:`~werkzeug.exceptions.HTTPException`78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from werkzeug.exceptions import HTTPException, BadRequest12from .helpers import json131415class JSONHTTPException(HTTPException):16 """A base class for HTTP exceptions with ``Content-Type:17 application/json``.1819 The ``description`` attribute of this class must set to a string (*not* an20 HTML string) which describes the error.2122 """2324 def get_body(self, environ):25 """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to26 return the description of this error in JSON format instead of HTML.2728 """29 return json.dumps(dict(description=self.get_description(environ)))3031 def get_headers(self, environ):32 """Returns a list of headers including ``Content-Type:33 application/json``.3435 """36 return [('Content-Type', 'application/json')]373839class JSONBadRequest(JSONHTTPException, BadRequest):40 """Represents an HTTP ``400 Bad Request`` error whose body contains an41 error message in JSON format instead of HTML format (as in the superclass).4243 """4445 #: The description of the error which occurred as a string.46 description = (47 'The browser (or proxy) sent a request that this server could not '48 'understand.'49 )
modified:flask/wrappers.py+1 added-38 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""1112from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase13from werkzeug.exceptions import BadRequest, HTTPException13from werkzeug.utils import cached_property1415from .exceptions import JSONBadRequest16from .debughelpers import attach_enctype_error_multidict17from .helpers import json, _assert_have_json18from .globals import _request_ctx_stack192021class JSONHTTPException(HTTPException):22 """A base class for HTTP exceptions with ``Content-Type:23 application/json``.2425 The ``description`` attribute of this class must set to a string (*not* an26 HTML string) which describes the error.2728 """2930 def get_body(self, environ):31 """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to32 return the description of this error in JSON format instead of HTML.3334 """35 return json.dumps(dict(description=self.get_description(environ)))3637 def get_headers(self, environ):38 """Returns a list of headers including ``Content-Type:39 application/json``.4041 """42 return [('Content-Type', 'application/json')]434445class JSONBadRequest(JSONHTTPException, BadRequest):46 """Represents an HTTP ``400 Bad Request`` error whose body contains an47 error message in JSON format instead of HTML format (as in the superclass).4849 """5051 #: The description of the error which occurred as a string.52 description = (53 'The browser (or proxy) sent a request that this server could not '54 'understand.'55 )565721class Request(RequestBase):22 """The request object used by default in Flask. Remembers the23 matched endpoint and view arguments.24
125 unmodified lines