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

Uploaded Source

Built Distribution

RichErr-0.2.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: RichErr-0.2.2.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.8.0-1042-azure

File hashes

Hashes for RichErr-0.2.2.tar.gz
Algorithm Hash digest
SHA256 636ef6a58d46d518782a95f502a90ca904899e672ac9bbf1d5bf1760f8bf78b8
MD5 72e93f0e5b2d5104d5add5bffee804e2
BLAKE2b-256 675cece92a489f09935a16de7c1b788290799936ac5c028539d2312b122a4f91

See more details on using hashes here.

File details

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

File metadata

  • Download URL: RichErr-0.2.2-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.8.0-1042-azure

File hashes

Hashes for RichErr-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6408865302664d20a32b21c0aa3630a9ea77a31217353ee7e9173756229cefca
MD5 b8365a21ac37bfc862a49a54998e67b4
BLAKE2b-256 da9bb8ffd22dbf5ee4fa59741e262572f7101cf5a5b79792e696da0f12824afe

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