Skip to main content

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

Metadata

Release files for fastapi-http-exceptions 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-http-exceptions 0.1.0
File Size Uploaded Provenance
fastapi_http_exceptions-0.1.0.tar.gz 7.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-http-exceptions 0.1.0
File Interpreter ABI Platform
fastapi_http_exceptions-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.9 kB

Release files / fastapi_http_exceptions-0.1.0.tar.gz

Download URL fastapi_http_exceptions-0.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
12ebbe21c2755cf2a5fab88c5ff65b9583643e0b5c9ddd90e300a39aba0f8673
BLAKE2b-256 checksum
How to use checksums
f369a5c0516b1817a1c345ce8fdf589b2bcea36413719cfcaa21d226b0ca2597
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / fastapi_http_exceptions-0.1.0-py3-none-any.whl

Download URL fastapi_http_exceptions-0.1.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c26316da2281936ba57d7da439b91b6c3c8d2d1e863895cc18b63e65a4bb36a
BLAKE2b-256 checksum
How to use checksums
3798ea967140d9e2a3490107a49cedeb5bf4aff2d3a63eab1ca6a854be6cda25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Security for fastapi-http-exceptions 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page