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):
    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)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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

Hashes for RichErr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a2b356b960cf2ce5748a453b5d085b3fc6f86c0164e00e15193122c7028d6f84
MD5 75f62a6de9ec0de4789dcd08c200041d
BLAKE2b-256 cc7ad76b8d877d42312492f6221bd4e58a8da42fb26ebdf774e525bf0016a17e

See more details on using hashes here.

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

Hashes for RichErr-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7fdf6f72b9895a26deb4f4ca2afb70856796c9b0804d121eb7feb29fd5332d6e
MD5 661a4759051b8b9180044470c7ee5805
BLAKE2b-256 c779c048576391f6484e070a432c547ec9daec7ee518869110a640e6b7302224

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