Skip to main content

Web based error utils

Project description

Web Errors v0.1.1

image image image style tests codecov

web_error is a set of exceptions and handlers for use in web apis to support easy error management and responses

Each exception easily marshals to JSON for use in api errors. Handlers for different web frameworks are provided.

Errors

The base web_error.error.HttpException accepts a message, debug_message, code and status (default 500)

And will render a response with status as the status code:

{
    "code": "code"
    "message": "message",
    "debug_message": "debug_message",
}

Some convenience Exceptions are provided, to create custom error subclass these and define message and code attributes.

  • web_error.error.ServerException provides status 500 errors
  • web_error.error.BadRequestException provides status 400 errors
  • web_error.error.UnauthorisedException provides status 401 errors
  • web_error.error.NotFoundException provides status 404 errors

Custom Errors

Subclassing the convenience classes provide a simple way to consistently raise the same error and message.

Code is an optional attribute to provide a unique value to parse in a frontend/client instead of matching against messages.

from web_error.error import NotFoundException


class UserNotFoundError(NotFoundException):
    message = "User not found."
    code = "E001"

Pyramid

Include the pyramid exception handlers in your config.

def main(global_config, **config_blob):
    config = Configurator(settings=config_blob)

    ...

    config.scan("web_error.handler.pyramid")

    return config.make_wsgi_app()

This will handle all unexpected errors, and any app specific errors.

@view_config(route_name="test", renderer="json")
def test(request):
    raise MyNotFoundError("debug message")

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

web_error-0.1.1.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

web_error-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file web_error-0.1.1.tar.gz.

File metadata

  • Download URL: web_error-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/5.3.6-zen1-1-zen

File hashes

Hashes for web_error-0.1.1.tar.gz
Algorithm Hash digest
SHA256 46b474befd85a225d86e3d84180f667b47c7b52767e862ff5ec3144f50e2ace7
MD5 64b1a92aed1b10876ac049cc8f48b99b
BLAKE2b-256 8841669db217b39859f9a34114850c4458f0a47f97fcaa2f4c4b6f9101d0dd37

See more details on using hashes here.

File details

Details for the file web_error-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: web_error-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/5.3.6-zen1-1-zen

File hashes

Hashes for web_error-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 95e4e1c1f06dbc21ae0f6d5bd0b8c7d9792e2a09487dff36ff13b2ee9f011ea5
MD5 14af1ae57b1af52b8a189013dd9fd8a5
BLAKE2b-256 7bc92bff62eba0bc7c8b793cf36af76dd7440141fbb72cebfd4b749c1c7b1f1f

See more details on using hashes here.

Supported by

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