AWS Abort
A lightweight Python package for handling HTTP error status codes by raising a custom exception with detailed, human-friendly messages.
Overview
The abort package simplifies error handling in web applications or any Python project that interacts with HTTP APIs. Instead of manually checking status codes and constructing error messages, abort provides a clean interface to raise an AbortException with a pre-defined message for common HTTP error status codes. The package also leverages Python’s built-in logging module to help you track and debug issues based on error severity.
Features
- Custom Exception: The
AbortExceptionclass encapsulates an HTTP status code and a descriptive error message. - Pre-defined Error Messages: Built-in messages for common HTTP status codes (400, 401, 403, 404, 405, 409, 415, 424, 429, 500) help clarify what went wrong.
- Over-right Default Error Messages: If you are not a fan of the built-in messages, you can change them with ease!
- Integrated Logging: Automatically logs error details at appropriate logging levels (debug, warning, critical) to facilitate troubleshooting.
Installation
You can install the package using pip:
pip install aws-abort
Usage
Import the abort function from the package and call it with an HTTP status code and an optional message. This will log the error and raise an AbortException with a combined error message.
Example
from abort import abort
# Trigger an HTTP 400 Bad Request error
abort(400, "The submitted data is missing required fields.")
When this code runs, it logs the error at the debug level and raises an AbortException with a message like:
"Bad request, check your code is right, required fields entered? The submitted data is missing required fields."
API Reference
AbortException
A custom exception for HTTP error status codes.
Attributes:
status_code(int): The HTTP status code.message(str): A detailed error message combining a base message with additional context.
Example:
from abort import AbortException, abort
try:
abort(404, "Lost!")
except AbortException as e:
print(e.status_code) # 404
print(e.message) # "Not found, we searched, and we searched, but nothing was there... Sorry. Lost!"
abort(status_code, message="")
Handles HTTP error status codes by logging the error and raising an AbortException.
Parameters:
status_code(int): The HTTP status code.message(str, optional): Additional context to append to the base error message.
Raises:
AbortException: Raised with a detailed message based on the status code.
Update Built-In Messages
You may not want the default built-in messages, which is fine! You can set them to anything you like!
Example
from abort import AbortException, abort
# Set a different 405 base message
AbortException.base_405 = "Whatcha doing?!"
try:
abort(405, "This is a GET request!")
except AbortException as e:
print(e.status_code) # 405
print(e.message) # "Whatcha doing?! This is a GET request!"
Logging Configuration
The package uses Python's logging module under the logger name abort. You can configure logging in your application to capture these messages:
import logging
logging.basicConfig(level=logging.DEBUG)
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions, issues, and feature requests are welcome!
Contact
For further inquiries or feedback, feel free to reach out via my website.
With abort, handling HTTP errors becomes more structured and maintainable. Enjoy seamless error management in your Python projects!
# That's all folks...
Metadata
Release files for aws-abort 0.0.1
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 | |
|---|---|---|---|---|
| aws_abort-0.0.1.tar.gz | 4.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_abort-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / aws_abort-0.0.1.tar.gz
| Download URL | aws_abort-0.0.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
287cad6700d4c9931ca5999d34942e41e5c7d086b75f82b6be32da9157baef4a
|
|
BLAKE2b-256 checksum How to use checksums |
1d17e08ac59649ce6302ca3e29a584dc8dbac38145d434617f22aaa135a07479
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Release files / aws_abort-0.0.1-py3-none-any.whl
| Download URL | aws_abort-0.0.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64a994139eb2e3d67e728b80b2a697dad5bfbad557b43a6ea83179f0988addba
|
|
BLAKE2b-256 checksum How to use checksums |
df1bba323d4305db0ce4739aaa950b76c7a9f0526a750208bedd94847d812fb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.6
|
Security for aws-abort 0.0.1
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.