RichErr


NameRichErr JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://adambrianbright.github.io/python-richerr/
SummaryRich errors (sort of)
upload_time2023-10-22 03:50:40
maintainer
docs_urlNone
authorBogdan Parfenov
requires_python>=3.12.0,<4.0
licenseMIT
keywords errors exceptions json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # 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) 
            

Raw data

            {
    "_id": null,
    "home_page": "https://adambrianbright.github.io/python-richerr/",
    "name": "RichErr",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.12.0,<4.0",
    "maintainer_email": "",
    "keywords": "errors,exceptions,json",
    "author": "Bogdan Parfenov",
    "author_email": "adam.brian.bright@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cf/ff/f8effcdc286c3b6c0c761324c5f7ae33eca9b70ed26a87d78e783619dc22/richerr-0.3.0.tar.gz",
    "platform": null,
    "description": "# Welcome\n\n[![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)  \n\n## RichErr\n\nRichErr is a tiny module that gives you basic error class, which can be used in JSON, dict, list, and other mutation\n\n```python example.py\nfrom richerr import RichErr\n\nprint(RichErr.convert(ValueError('Hello world!')).json(indent=2))\n```\n\n```json5\n{\n  \"error\": {\n    \"code\": 400,\n    \"exception\": \"BadRequest\",\n    \"message\": \"Hello world!\",\n    \"caused_by\": {\n      \"error\": {\n        \"code\": 500,\n        \"exception\": \"ValueError\",\n        \"message\": \"Hello world!\",\n        \"caused_by\": null\n      }\n    }\n  }\n}\n```\n\n## Installation\n\n### Poetry\n\n```shell\npoetry add RichErr\n```\n\n### PIP\n\n```shell\npip install RichErr\n```\n\n## Requirements\n\n- [x] Python 3.12+\n- [x] No package dependencies\n\n## Plugins\n\n- [x] Supported Django Validation and ObjectNotFound errors\n- [x] Supported DRF Validation errors\n- [x] Supported Pydantic Validation errors\n\n### Want to add your own error conversion?\n\nAdd direct conversion\n\n```python\nfrom richerr import RichErr, GatewayTimeout\n\n\nclass MyTimeoutError(IOError): ...\n\n\nRichErr.add_conversion(MyTimeoutError, GatewayTimeout)\n```\n\nOr add conversion method\n\n```python\nfrom richerr import RichErr\n\n\nclass MyTimeoutError(IOError): ...\n\n\ndef _convert(err: MyTimeoutError):\n    return RichErr.from_error(err, message='Something happened', code=500, name='MyTimeoutError')\n\n\nRichErr.add_conversion(MyTimeoutError, _convert)\n```\n\n!!!\nSubclasses will be checked before their parent, if multiple classes in same MRO will be registered.\n!!!\n\n [![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) ",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Rich errors (sort of)",
    "version": "0.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/AdamBrianBright/python-richerr/issues",
        "ChangeLog": "https://adambrianbright.github.io/python-richerr/changelog",
        "Contact Author": "https://vk.com/adam_bright",
        "Documentation": "https://adambrianbright.github.io/python-richerr/",
        "Homepage": "https://adambrianbright.github.io/python-richerr/",
        "Repository": "https://github.com/AdamBrianBright/python-richerr"
    },
    "split_keywords": [
        "errors",
        "exceptions",
        "json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17f1d2e64e1b4c788d4dcb08925183a0d7155352bc5639e6775ae9a4bf1d42cf",
                "md5": "792cbcfd049e8821b5f01bbedd44ed82",
                "sha256": "2282dacf296361b9edd0a8e84611cdd692de6f4cbe681189fbed419e06997e25"
            },
            "downloads": -1,
            "filename": "richerr-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "792cbcfd049e8821b5f01bbedd44ed82",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12.0,<4.0",
            "size": 5913,
            "upload_time": "2023-10-22T03:50:38",
            "upload_time_iso_8601": "2023-10-22T03:50:38.805026Z",
            "url": "https://files.pythonhosted.org/packages/17/f1/d2e64e1b4c788d4dcb08925183a0d7155352bc5639e6775ae9a4bf1d42cf/richerr-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cffff8effcdc286c3b6c0c761324c5f7ae33eca9b70ed26a87d78e783619dc22",
                "md5": "d157be28f9c482895561996a81a639af",
                "sha256": "a019461a1ed1e3698d74850bcac181d354b62cb5cb1db1485b641c2d02602088"
            },
            "downloads": -1,
            "filename": "richerr-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d157be28f9c482895561996a81a639af",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12.0,<4.0",
            "size": 5569,
            "upload_time": "2023-10-22T03:50:40",
            "upload_time_iso_8601": "2023-10-22T03:50:40.293152Z",
            "url": "https://files.pythonhosted.org/packages/cf/ff/f8effcdc286c3b6c0c761324c5f7ae33eca9b70ed26a87d78e783619dc22/richerr-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-22 03:50:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AdamBrianBright",
    "github_project": "python-richerr",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "richerr"
}
        
Elapsed time: 0.13241s