FastAPI Event
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.9.tar.gz
(11.3 kB
view hashes)
Built Distribution
Close
Hashes for fastapi_exception-1.3.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 829341018c9c50f9fa7ffbd01cc8dd76b792edeec51fbccafc0f3140ee2f60ca |
|
MD5 | f29d3d62ce6d7276e93a82bb68870b86 |
|
BLAKE2b-256 | 7f3562109879f199659a31d5a734859ed6bddda0c1accd1ed4ce565f7e2e3e96 |