Skip to main content

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 | BaseException):
    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.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

RichErr-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file RichErr-0.1.0.tar.gz.

File metadata

  • Download URL: RichErr-0.1.0.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

Hashes for RichErr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a52a7ddde9ac01fa33ba25b67776fbe1361c3dcb3af9105389b62cef716d7916
MD5 710ae00f863fdfd0bce2ec4f769babfe
BLAKE2b-256 11c8192da3589eaea2398ca4a1788754f16f3468b3ce646368028644c2ebc647

See more details on using hashes here.

File details

Details for the file RichErr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: RichErr-0.1.0-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

Hashes for RichErr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 612d5283b4a13793ea27a2b0f206442314a1c198918ddb5a060a4ade012917f2
MD5 e43b499d143681180a894a16d61f4dc4
BLAKE2b-256 d1ef06b8940ff0c2b64d87cddf57537e800d4ab0521676264384a6a4de2a1aef

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