Web based error utils
Project description
Web Errors v0.2.2
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.ServerExceptionprovides status 500 errorsweb_error.error.BadRequestExceptionprovides status 400 errorsweb_error.error.UnauthorisedExceptionprovides status 401 errorsweb_error.error.NotFoundExceptionprovides 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 UserNotFoundError("debug message")
Flask
Register the error handler with your application
app.register_error_handler(Exception, web_error.handler.flask.exception_handler)
Aiohttp
Decorate your views with the error handler.
@web_error.handler.aiohttp.view_error_handler
async def user(self):
raise UserNotFoundError("debug message")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file web_error-0.2.2.tar.gz.
File metadata
- Download URL: web_error-0.2.2.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.7.9 Linux/5.8.13-zen1-2-zen
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f147eaf016f0f0d5863297047072205f9873eaedb7bc58b276967ade42b8da2c
|
|
| MD5 |
f950ab122a2dec0aadd6b53e2f30802d
|
|
| BLAKE2b-256 |
99200c7f42ad49a9478c4ae7192360043dbc0458fec6a0dc4452ee77146c540b
|
File details
Details for the file web_error-0.2.2-py3-none-any.whl.
File metadata
- Download URL: web_error-0.2.2-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.3 CPython/3.7.9 Linux/5.8.13-zen1-2-zen
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c73f3f0377435af0dc93fb497354ec7fadd8438b9d8245afbc55107e201c552e
|
|
| MD5 |
255741779a9745dfd0e177f27c04c508
|
|
| BLAKE2b-256 |
a96188e4985f7195473ad21cd28209c433918abe2e26e04411882f7ecacd4b54
|