Skip to content

Latest commit

 

History

History
92 lines (60 loc) · 2.15 KB

index.md

File metadata and controls

92 lines (60 loc) · 2.15 KB

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