Skip to main content

Common exceptions for FastAPI

Project description

FastAPI exceptions

Introduction

fastapi-exceptions is a set of standard http exceptions based on starlette exceptions.

Installation

> pip install fastapi-exceptions

Usage

Instead of duplication of exceptions codes and their details for standard cases:

from fastapi import HTTPException
from starlette import status

# some app logic ...
    raise HTTPException(
        status_code=status.HTTP_401_UNAUTHORIZED,
        detail='Authentication credentials were not provided',
    )

you can simply import exceptions and use wherever you need:

from fastapi_exceptions.exceptions import NotAuthenticated

# some app logic ...
    raise NotAuthenticated()

and, of course, modify details if needed:

# some app logic ...
    raise NotAuthenticated(detail='No authentication header')

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

fastapi-exceptions-0.1.0.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

fastapi_exceptions-0.1.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

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