FastAPI Exception
Project description
FastAPI Exception
Installation
pip install fastapi-exception
How to use
fastapi_exception exposes exceptions
- FastApiException
- ForbiddenException
- NotFoundException
- GoneException
- BadRequestException
- DirectResponseException
- EntityNotFoundException
- UnauthorizedException
fastapi_exception exposes errors
- DuplicateError
- StringTooLongError
- StringTooShortError
- MissingError
Configuration
# config/exception.py
from config.i18n import i18n_service
from fastapi_exception import FastApiException
FastApiException.init()
FastApiException.init(translator_service=i18n_service) # pass translator_service if we integrate with i18n
Use exceptions with throw_validation
from fastapi_exception import throw_validation
throw_validation(type='value_error', loc=('body', 'key'))
Use errors with throw_validation_with_exception
from fastapi_exception import throw_validation_with_exception, MissingError
raise throw_validation_with_exception(MissingError(('body', 'product media or galleries')))
Customize Exception
from fastapi_exception import ValidationErrorDetail
class InvalidDataTypeError(ValidationErrorDetail):
error_type = 'datatype.invalid'
def __init__(
self,
loc: tuple[int | str, ...],
ctx: dict[str, dict[str, Any]] | None = {},
input: dict[str, Any] = {},
):
super().__init__(self.error_type, loc, '', input, ctx)
throw_validation_with_exception(InvalidDataTypeError(('body', 'value')))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_exception-1.3.10.tar.gz
(11.3 kB
view details)
Built Distribution
File details
Details for the file fastapi_exception-1.3.10.tar.gz
.
File metadata
- Download URL: fastapi_exception-1.3.10.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7849ab9853d3c46c1cb48eda1ff63574eabaa59ff220ff6f8a80cf23d101eee |
|
MD5 | a098318c7d4bc4b413d5c0f1f3446160 |
|
BLAKE2b-256 | 605be0b72e308321ce4b763b4a0ea258cc010ebd96ea6d1c78c551c7c9930094 |
File details
Details for the file fastapi_exception-1.3.10-py3-none-any.whl
.
File metadata
- Download URL: fastapi_exception-1.3.10-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a66705cb84e2bb38a64f4b05229a02caa8368855bd84398db4ce6496e96d4895 |
|
MD5 | 834267f28dc8822ccfbedcb7eeddac22 |
|
BLAKE2b-256 | e153158f83e20f8ea1e434eb90e0ec90cc061ce04c24d16cb60600777533b953 |