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.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. !!!

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

Uploaded Source

Built Distribution

RichErr-0.2.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: RichErr-0.2.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.8.0-1042-azure

File hashes

Hashes for RichErr-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3beaec699027184dc9c9d719f1f9d3813139a76f4bab7e298fdfff7b0db90480
MD5 89086dd4e87e7e1806ea9de89bef33f9
BLAKE2b-256 36b7cd815184f61776c406998d27cddec4e4ef421b1ae429dee1ad26473f3371

See more details on using hashes here.

File details

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

File metadata

  • Download URL: RichErr-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.10.0 Linux/5.8.0-1042-azure

File hashes

Hashes for RichErr-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35723e041e8f104576f5e16bbe1b41c8141dcd902d585d51c0297ded895ce63b
MD5 f3d6e9e7ed156944ef0cd6e37cd5cf0c
BLAKE2b-256 f768bb42df1640816ae4f5fad0b7c6e10e289d663da211f5817a4674127a4d6f

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