Metadata-Version: 2.1
Name: RichErr
Version: 0.3.0
Summary: Rich errors (sort of)
Home-page: https://adambrianbright.github.io/python-richerr/
License: MIT
Keywords: errors,exceptions,json
Author: Bogdan Parfenov
Author-email: adam.brian.bright@gmail.com
Requires-Python: >=3.12.0,<4.0
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Natural Language :: Russian
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
Classifier: Operating System :: OS Independent
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Typing :: Typed
Project-URL: Bug Tracker, https://github.com/AdamBrianBright/python-richerr/issues
Project-URL: ChangeLog, https://adambrianbright.github.io/python-richerr/changelog
Project-URL: Contact Author, https://vk.com/adam_bright
Project-URL: Documentation, https://adambrianbright.github.io/python-richerr/
Project-URL: Repository, https://github.com/AdamBrianBright/python-richerr
Description-Content-Type: text/markdown

# Welcome

[![PyPI version](https://badge.fury.io/py/richerr.svg)](https://badge.fury.io/py/richerr)  [![codecov](https://codecov.io/gh/AdamBrianBright/python-richerr/branch/master/graph/badge.svg?token=DDBNKVLZWH)](https://codecov.io/gh/AdamBrianBright/python-richerr) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAdamBrianBright%2Fpython-richerr.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FAdamBrianBright%2Fpython-richerr?ref=badge_shield)  

## RichErr

RichErr is a tiny module that gives you basic error class, which can be used in JSON, dict, list, and other mutation

```python example.py
from richerr import RichErr

print(RichErr.convert(ValueError('Hello world!')).json(indent=2))
```

```json5
{
  "error": {
    "code": 400,
    "exception": "BadRequest",
    "message": "Hello world!",
    "caused_by": {
      "error": {
        "code": 500,
        "exception": "ValueError",
        "message": "Hello world!",
        "caused_by": null
      }
    }
  }
}
```

## Installation

### Poetry

```shell
poetry add RichErr
```

### PIP

```shell
pip install RichErr
```

## Requirements

- [x] Python 3.12+
- [x] No package dependencies

## Plugins

- [x] Supported Django Validation and ObjectNotFound errors
- [x] Supported DRF Validation errors
- [x] Supported Pydantic Validation errors

### Want to add your own error conversion?

Add direct conversion

```python
from richerr import RichErr, GatewayTimeout


class MyTimeoutError(IOError): ...


RichErr.add_conversion(MyTimeoutError, GatewayTimeout)
```

Or add conversion method

```python
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](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAdamBrianBright%2Fpython-richerr.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FAdamBrianBright%2Fpython-richerr?ref=badge_large) 
