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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: RichErr-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 297fefa08b6802c59c030d176f2dac26939de21848828e6de927364b1e051113
MD5 d0afcdf9cde062f4642776c603537fad
BLAKE2b-256 10b3f48cded16eccf09ecef417283efa9e99ed1dd18633ed5c093248c9caac2e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: RichErr-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e675a2305c71321e32019ea4d9bf6908c9baa6a526f087ddde49247110178119
MD5 0d23fce0dce7769be29ca17cb3f21fb3
BLAKE2b-256 db11de0ed709e0ca84b02df1a988e440c5803c741ac6d608cada4a64c1bac42d

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