Name | abs-exception-core JSON |
Version |
0.1.4
JSON |
| download |
home_page | None |
Summary | Shared base exception utilities for FastAPI apps. |
upload_time | 2025-08-07 11:50:35 |
maintainer | None |
docs_url | None |
author | AutoBridgeSystems |
requires_python | <4.0,>=3.12 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Exception Core Package
A comprehensive exception handling package for FastAPI applications that provides standardized error responses and exception handling.
## Features
- Pre-defined HTTP exceptions for common error scenarios
- Dynamic error creation for custom scenarios
- Standardized error response format
- Request validation error handling
## Installation
```bash
pip install abs-exception-core
```
## Usage
### 1. Import and Register Exception Handlers
```python
from fastapi import FastAPI
from abs_exception_core.exception_handlers import (
request_validation_exception_handler,
global_exception_handler,
# ... other handlers
)
app = FastAPI()
# Register exception handlers
app.add_exception_handler(RequestValidationError, request_validation_exception_handler)
app.add_exception_handler(Exception, global_exception_handler)
```
### 2. Using Pre-defined Exceptions
```python
from abs_exception_core.exceptions import (
NotFoundError,
ValidationError,
AuthError,
GenericHttpError,
# ... other exceptions
)
# Example usage in a route
@app.get("/items/{item_id}")
async def get_item(item_id: int):
if not item_exists(item_id):
raise NotFoundError(detail="Item not found")
if not has_permission():
raise AuthError(detail="Insufficient permissions")
```
### 3. Using Generic Error
The `GenericHttpError` class allows you to create custom HTTP exceptions with any status code:
```python
# Create a custom error with status code 418
error = GenericHttpError(
status_code=418,
detail="I'm a teapot",
headers={"X-Custom-Header": "value"}
)
# Create a custom error with just status code and message
error = GenericHttpError(
status_code=451,
detail="Unavailable For Legal Reasons"
)
# Create a custom error with just status code
error = GenericHttpError(status_code=402)
```
### Available Exceptions
- `DuplicatedError` (409 Conflict)
- `AuthError` (403 Forbidden)
- `NotFoundError` (404 Not Found)
- `ValidationError` (422 Unprocessable Entity)
- `PermissionDeniedError` (403 Forbidden)
- `UnauthorizedError` (401 Unauthorized)
- `BadRequestError` (400 Bad Request)
- `ConflictError` (409 Conflict)
- `InternalServerError` (500 Internal Server Error)
- `RateLimitExceededError` (429 Too Many Requests)
- `ServiceUnavailableError` (503 Service Unavailable)
- `GenericHttpError` (Custom Status Code) - For creating custom HTTP exceptions
### Error Response Format
All errors follow a standardized format:
```json
{
"message": "Error message",
"error": "Detailed error description",
"type": "ErrorType",
"details": {
"path": "/api/endpoint",
"method": "GET"
},
"errors": [
{
"field": "field_name",
"message": "Validation message",
"type": "error_type",
"input_value": "invalid_value"
}
]
}
```
## Best Practices
1. Use the most specific exception type that matches your error scenario
2. For custom status codes or scenarios not covered by standard exceptions, use `GenericHttpError`
3. Provide meaningful error details to help clients understand and resolve issues
4. Use custom headers sparingly and only when they provide additional value
5. Follow the standardized error response format for consistency
## License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "abs-exception-core",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.12",
"maintainer_email": null,
"keywords": null,
"author": "AutoBridgeSystems",
"author_email": "info@autobridgesystems.com",
"download_url": "https://files.pythonhosted.org/packages/04/16/db5a5d1daf8c97b12b61884233edd42d0de9f0eb681f6cfba0a85e1dae38/abs_exception_core-0.1.4.tar.gz",
"platform": null,
"description": "# Exception Core Package\n\nA comprehensive exception handling package for FastAPI applications that provides standardized error responses and exception handling.\n\n## Features\n\n- Pre-defined HTTP exceptions for common error scenarios\n- Dynamic error creation for custom scenarios\n- Standardized error response format\n- Request validation error handling\n\n## Installation\n\n```bash\npip install abs-exception-core\n```\n\n## Usage\n\n### 1. Import and Register Exception Handlers\n\n```python\nfrom fastapi import FastAPI\nfrom abs_exception_core.exception_handlers import (\n request_validation_exception_handler,\n global_exception_handler,\n # ... other handlers\n)\n\napp = FastAPI()\n\n# Register exception handlers\napp.add_exception_handler(RequestValidationError, request_validation_exception_handler)\napp.add_exception_handler(Exception, global_exception_handler)\n```\n\n### 2. Using Pre-defined Exceptions\n\n```python\nfrom abs_exception_core.exceptions import (\n NotFoundError,\n ValidationError,\n AuthError,\n GenericHttpError,\n # ... other exceptions\n)\n\n# Example usage in a route\n@app.get(\"/items/{item_id}\")\nasync def get_item(item_id: int):\n if not item_exists(item_id):\n raise NotFoundError(detail=\"Item not found\")\n \n if not has_permission():\n raise AuthError(detail=\"Insufficient permissions\")\n```\n\n### 3. Using Generic Error\n\nThe `GenericHttpError` class allows you to create custom HTTP exceptions with any status code:\n\n```python\n# Create a custom error with status code 418\nerror = GenericHttpError(\n status_code=418,\n detail=\"I'm a teapot\",\n headers={\"X-Custom-Header\": \"value\"}\n)\n\n# Create a custom error with just status code and message\nerror = GenericHttpError(\n status_code=451,\n detail=\"Unavailable For Legal Reasons\"\n)\n\n# Create a custom error with just status code\nerror = GenericHttpError(status_code=402)\n```\n\n### Available Exceptions\n\n- `DuplicatedError` (409 Conflict)\n- `AuthError` (403 Forbidden)\n- `NotFoundError` (404 Not Found)\n- `ValidationError` (422 Unprocessable Entity)\n- `PermissionDeniedError` (403 Forbidden)\n- `UnauthorizedError` (401 Unauthorized)\n- `BadRequestError` (400 Bad Request)\n- `ConflictError` (409 Conflict)\n- `InternalServerError` (500 Internal Server Error)\n- `RateLimitExceededError` (429 Too Many Requests)\n- `ServiceUnavailableError` (503 Service Unavailable)\n- `GenericHttpError` (Custom Status Code) - For creating custom HTTP exceptions\n\n### Error Response Format\n\nAll errors follow a standardized format:\n\n```json\n{\n \"message\": \"Error message\",\n \"error\": \"Detailed error description\",\n \"type\": \"ErrorType\",\n \"details\": {\n \"path\": \"/api/endpoint\",\n \"method\": \"GET\"\n },\n \"errors\": [\n {\n \"field\": \"field_name\",\n \"message\": \"Validation message\",\n \"type\": \"error_type\",\n \"input_value\": \"invalid_value\"\n }\n ]\n}\n```\n\n## Best Practices\n\n1. Use the most specific exception type that matches your error scenario\n2. For custom status codes or scenarios not covered by standard exceptions, use `GenericHttpError`\n3. Provide meaningful error details to help clients understand and resolve issues\n4. Use custom headers sparingly and only when they provide additional value\n5. Follow the standardized error response format for consistency\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Shared base exception utilities for FastAPI apps.",
"version": "0.1.4",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "051ab9d01f0086d269985511c78a6d945ba214034ef7f0e9f9d53248be89a8ea",
"md5": "9eb63b6f5bece43b55b443a7321b4ca7",
"sha256": "5f82de447f9b69640d1091541d223aff2c4baf909a702088fb81a025f9c7a335"
},
"downloads": -1,
"filename": "abs_exception_core-0.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9eb63b6f5bece43b55b443a7321b4ca7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.12",
"size": 4724,
"upload_time": "2025-08-07T11:50:34",
"upload_time_iso_8601": "2025-08-07T11:50:34.065386Z",
"url": "https://files.pythonhosted.org/packages/05/1a/b9d01f0086d269985511c78a6d945ba214034ef7f0e9f9d53248be89a8ea/abs_exception_core-0.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0416db5a5d1daf8c97b12b61884233edd42d0de9f0eb681f6cfba0a85e1dae38",
"md5": "a5242f55849fcac8fe5946779fcd12a8",
"sha256": "5c10bd962f2254d2d560f9ec3a89fa6d8ea8a1da98345f711d2291cf65f69e41"
},
"downloads": -1,
"filename": "abs_exception_core-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "a5242f55849fcac8fe5946779fcd12a8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.12",
"size": 3597,
"upload_time": "2025-08-07T11:50:35",
"upload_time_iso_8601": "2025-08-07T11:50:35.056953Z",
"url": "https://files.pythonhosted.org/packages/04/16/db5a5d1daf8c97b12b61884233edd42d0de9f0eb681f6cfba0a85e1dae38/abs_exception_core-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-07 11:50:35",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "abs-exception-core"
}