Skip to content

kholodnyi/fastapi-exceptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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')

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages