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": "BadRequest",
"message": "Hello world!",
"caused_by": {
"error": {
"code": 500,
"exception": "ValueError",
"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.2.3.tar.gz
(6.0 kB
view details)
Built Distribution
File details
Details for the file RichErr-0.2.3.tar.gz
.
File metadata
- Download URL: RichErr-0.2.3.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.11.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07ac7017e369dfd52af46233f880ffda68da9bc6c71fc69be54a98e8d39fb3e3 |
|
MD5 | 8a7fbe88402ab10ae47f61d310340e97 |
|
BLAKE2b-256 | a758bb23b490b151069b578437a1c7745cf77494eea263c324b37acc39b25c76 |
File details
Details for the file RichErr-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: RichErr-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.11.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 272dd7f2e93f2255688e3d44ed6f12056db414d671bebfd57bc9c9c0be60adb5 |
|
MD5 | ffd76c2e3e328dc5f05f9cb9ab53b08c |
|
BLAKE2b-256 | 95796c26d9cbfe2f93588012ac102c6e026ca39d9f3100d9a2f5b6ab3f7088a2 |