Custom HTTP Exceptions for Starlette
Project Description
This library provides a set of custom HTTP exceptions for Starlette applications, inspired by Starlette'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 starlette-http-exceptions
Usage
Instead of duplicating exception handling code throughout your Starlette 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 starlette_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 starlette-http-exceptions 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| starlette_http_exceptions-0.1.2.tar.gz | 8.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| starlette_http_exceptions-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / starlette_http_exceptions-0.1.2.tar.gz
| Download URL | starlette_http_exceptions-0.1.2.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5185204e379650b8b3abe020f667e8ded80b4163b05de6c59d686a01f3e8e679
|
|
BLAKE2b-256 checksum How to use checksums |
e7d76b34d59e817edaa42991d477655653274d7201a3091c5f23e95645c7d501
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.26
|
Release files / starlette_http_exceptions-0.1.2-py3-none-any.whl
| Download URL | starlette_http_exceptions-0.1.2-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14b9d65219368441d3773e8c7dd1d02f8603bb210b6ec92790f8ade068caa230
|
|
BLAKE2b-256 checksum How to use checksums |
b2b3e24d36085c5b8ef3d6dd7be9ab250061ae2f07464d596a5a14dda79d490c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.26
|
Security for starlette-http-exceptions 0.1.2
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.