Skip to main content

Rich errors (sort of)

Project description

Welcome

PyPI version codecov FOSSA Status

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.12+
  • 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. !!!

FOSSA Status

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

Uploaded Source

Built Distribution

richerr-0.3.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file richerr-0.3.0.tar.gz.

File metadata

  • Download URL: richerr-0.3.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-1014-azure

File hashes

Hashes for richerr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a019461a1ed1e3698d74850bcac181d354b62cb5cb1db1485b641c2d02602088
MD5 d157be28f9c482895561996a81a639af
BLAKE2b-256 cffff8effcdc286c3b6c0c761324c5f7ae33eca9b70ed26a87d78e783619dc22

See more details on using hashes here.

File details

Details for the file richerr-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: richerr-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-1014-azure

File hashes

Hashes for richerr-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2282dacf296361b9edd0a8e84611cdd692de6f4cbe681189fbed419e06997e25
MD5 792cbcfd049e8821b5f01bbedd44ed82
BLAKE2b-256 17f1d2e64e1b4c788d4dcb08925183a0d7155352bc5639e6775ae9a4bf1d42cf

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