Skip to main content

Library that provides a easy to use set of http errors along with useful descriptions

Project description

Http errors provide a list of easy to test and descriptive set of python errors.

Code example

Raising exception

from httperrors import BadRequestError
class View(BaseView):
    def validate(self, request):
        ...
        if not request.body.is_json():
            raise BadRequestError(
                error_message="You must provide a JSON body",
                error_code="NOT_A_JSON_BODY_ERROR",
            )
    def run(self,request):
        ...

Serialization

You will be able to catch this exception somewhere in the flow of your application, map it and serialize it to the corresponding request.

from httperrors import BadRequestError
class BaseView:
def __init__(self):
    try:
        self.validate()
    except BadRequestError as e:
        return json_response(
            status_code=e.status_code,
            body=e.serialize()
        )

Testing

You will be able to easily test your application

from httperrors import BadRequestError
class TestView:
def test_it_raises_bad_request_error_not_json_body(self):
    view = View()
    request = Mock()
    request.body.is_json.return_value = False
    with pytest.raises(BadRequestError) as error:
        view.validate()
        assert error.error_code == "NOT_A_JSON_BODY_ERROR"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

httperrors-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

httperrors-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file httperrors-1.0.0.tar.gz.

File metadata

  • Download URL: httperrors-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for httperrors-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0fb2ac562f7c46ce4a82d55dfb90381074faff34f0127315221ed3023915e91f
MD5 7bcb5c5c30eca4bf29056e38b9638455
BLAKE2b-256 897ab8379d2af0ad6d025a272004af3b6e0b0e9dbd923a77e8046deb3e8547b9

See more details on using hashes here.

File details

Details for the file httperrors-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: httperrors-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.8

File hashes

Hashes for httperrors-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7cbd841e930cd5249d0f63c55c4fd9f5b40b4ed0addccb66553bc987573c395
MD5 1463a0d60847813f97d70c8485db8a1f
BLAKE2b-256 7bcd731bcbbf37444f3049a7f045cd0c528fa88ba92a62008cb1d812d2e18478

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page