Rich errors (sort of)
Project description
Welcome
RichErr
RichErr is a tiny module that gives you basic error class, which can be used in JSON, dict, list, and other mutation
from richerr import RichErr
print(RichErr.convert(ValueError('Hello world!')).json(indent=2))
{
"error": {
"code": 400,
"exception": "BadRequestException",
"message": "Hello world!",
"caused_by": {
"error": {
"code": 500,
"exception": "ValueErrorException",
"message": "Hello world!",
"caused_by": null
}
}
}
}
Installation
Poetry
poetry add RichErr
PIP
pip install RichErr
Requirements
- Python 3.10+
- No package dependencies
Plugins
- Supported Django Validation and ObjectNotFound errors
- Supported DRF Validation errors
- Supported Pydantic Validation errors
Want to add your own error conversion?
Add direct conversion
from richerr import RichErr, GatewayTimeout
class MyTimeoutError(IOError): ...
RichErr.add_conversion(MyTimeoutError, GatewayTimeout)
Or add conversion method
from richerr import RichErr
class MyTimeoutError(IOError): ...
def _convert(err: MyTimeoutError):
return RichErr.from_error(err, message='Something happened', code=500, name='MyTimeoutError')
RichErr.add_conversion(MyTimeoutError, _convert)
!!! Subclasses will be checked before their parent, if multiple classes in same MRO will be registered. !!!
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
RichErr-0.1.2.tar.gz
(5.6 kB
view details)
Built Distribution
File details
Details for the file RichErr-0.1.2.tar.gz
.
File metadata
- Download URL: RichErr-0.1.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.6 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2b356b960cf2ce5748a453b5d085b3fc6f86c0164e00e15193122c7028d6f84 |
|
MD5 | 75f62a6de9ec0de4789dcd08c200041d |
|
BLAKE2b-256 | cc7ad76b8d877d42312492f6221bd4e58a8da42fb26ebdf774e525bf0016a17e |
File details
Details for the file RichErr-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: RichErr-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.8 CPython/3.9.6 Darwin/20.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fdf6f72b9895a26deb4f4ca2afb70856796c9b0804d121eb7feb29fd5332d6e |
|
MD5 | 661a4759051b8b9180044470c7ee5805 |
|
BLAKE2b-256 | c779c048576391f6484e070a432c547ec9daec7ee518869110a640e6b7302224 |