A library for handling HTTP exceptions in FastAPI applications, providing a set of predefined exceptions for common HTTP error statuses like 404, 403, 401, etc., to make error handling in APIs more streamlined and maintainable.
Project description
Custom HTTP Exceptions for FastAPI
Project Description
This library provides a set of custom HTTP exceptions for FastAPI applications, inspired by FastAPI's built-in exceptions. With these custom exceptions, you can simplify error handling by using pre-configured, standard HTTP exception classes tailored to common HTTP status codes.
Installation
To get started, simply install the package via pip:
pip install fastapi-http-exceptions
Usage
Instead of duplicating exception handling code throughout your FastAPI application, you can use the pre-defined exceptions from this library. Raise these exceptions directly without worrying about writing boilerplate code for every status code.
Example 1: Raising Unauthorized Exception
Instead of manually creating HTTP exceptions like this:
from fastapi import HTTPException, status
# Some application logic...
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Authentication credentials were not provided"
)
You can import and use a pre-configured exception like this:
from fastapi_http_exceptions import UnauthorizedException
# Some application logic...
raise UnauthorizedException(
detail="Authentication credentials were not provided",
headers={}
)
Available Exceptions
| Exception | Status Code |
|---|---|
BadRequestException |
400 Bad Request |
UnauthorizedException |
401 Unauthorized |
ForbiddenException |
403 Forbidden |
NotFoundException |
404 Not Found |
MethodNotAllowedException |
405 Method Not Allowed |
NotAcceptableException |
406 Not Acceptable |
ProxyAuthenticationRequiredException |
407 Proxy Authentication Required |
RequestTimeoutException |
408 Request Timeout |
ConflictException |
409 Conflict |
GoneException |
410 Gone |
LengthRequiredException |
411 Length Required |
PreconditionFailedException |
412 Precondition Failed |
RequestEntityTooLargeException |
413 Request Entity Too Large |
RequestUriTooLongException |
414 Request URI Too Long |
UnsupportedMediaTypeException |
415 Unsupported Media Type |
RequestedRangeNotSatisfiableException |
416 Requested Range Not Satisfiable |
ExpectationFailedException |
417 Expectation Failed |
ImATeapotException |
418 I'm a Teapot |
MisdirectedRequestException |
421 Misdirected Request |
UnprocessableEntityException |
422 Unprocessable Entity |
LockedException |
423 Locked |
FailedDependencyException |
424 Failed Dependency |
UpgradeRequiredException |
426 Upgrade Required |
PreconditionRequiredException |
428 Precondition Required |
TooManyRequestsException |
429 Too Many Requests |
RequestHeaderFieldsTooLargeException |
431 Request Header Fields Too Large |
UnavailableForLegalReasonsException |
451 Unavailable For Legal Reasons |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_http_exceptions-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_http_exceptions-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12ebbe21c2755cf2a5fab88c5ff65b9583643e0b5c9ddd90e300a39aba0f8673
|
|
| MD5 |
a7984e1c9912a38212b0f9bedbcbb73f
|
|
| BLAKE2b-256 |
f369a5c0516b1817a1c345ce8fdf589b2bcea36413719cfcaa21d226b0ca2597
|
File details
Details for the file fastapi_http_exceptions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_http_exceptions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c26316da2281936ba57d7da439b91b6c3c8d2d1e863895cc18b63e65a4bb36a
|
|
| MD5 |
9c58568117e6cec3d9c6eb50f51d76f7
|
|
| BLAKE2b-256 |
3798ea967140d9e2a3490107a49cedeb5bf4aff2d3a63eab1ca6a854be6cda25
|