Metadata-Version: 2.1
Name: fastapi_router_handler
Version: 0.1.0
Summary: Python Fastapi's general exception handler
License: MIT-3
Author: KyungHo Kim
Author-email: qqaa3030@gmail.com
Requires-Python: >=3.10,<4.0
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: fastapi (>=0.115.6,<0.116.0)
Requires-Dist: httpx (>=0.28.1,<0.29.0)
Description-Content-Type: text/markdown

# FastAPI Router Handler

FastAPI Router Handler is a package designed to help you manage exception handling in FastAPI applications in a clean and consistent way. This package allows you to handle exceptions gracefully in router handlers while maintaining a consistent response format.

## Key Features

- Asynchronous exception handling support
- Custom logging integration
- Consistent error response format
- Global exception handling through middleware
- Customizable error messages

## Installation

```bash
pip install fastapi-router-handler
```

## Usage

### Basic Example

```python
from fastapi import FastAPI
from fastapi_router_handler import ExceptionHandler

app = FastAPI()
exception_handler = ExceptionHandler()

@app.get("/example")
async def example_endpoint():
    return await exception_handler.exception_handler(
        lambda: {"message": "success"}
    )

@app.get("/error-example")
async def error_endpoint():
    return await exception_handler.exception_handler(
        lambda: raise_error(),  # Function that raises an error
        e_code=400,
        e_msg="Custom error message"
    )
```

### Using Custom Logger

```python
import logging
from fastapi_router_handler import ExceptionHandler

logger = logging.getLogger(__name__)
exception_handler = ExceptionHandler(logger=logger)
```

## Response Examples

### Success Response

```json
{
  "message": "success"
}
```

### Error Response

```json
{
    "detail": "Internal Server Error",  # Requires e_msg setting, default: "Internal Server Error"
    "status_code": 500  # Requires e_code setting, default: 500
}
```

## License

MIT License

---

## Contributing

Contributions are welcome! Please feel free to submit a pull request.

- Github: [@Jin-Doh/fastapi-router-handler](https://github.com/Jin-Doh/fastapi-router-handler)
- PyPI: [@fastapi-router-handler](https://pypi.org/project/fastapi-router-handler/)
- Email: [qqaa3030@gmail.com](mailto:qqaa3030@gmail.com)

