Axum Error Handler
A procedural macro for generating standardized error responses in Axum applications. This crate provides a derive macro that automatically implements the IntoResponse
trait for your error enums, creating consistent JSON error responses with proper HTTP status codes.
Features
- 🚀 Easy Integration: Simple derive macro for error enums
- 📝 Consistent Format: Standardized JSON error responses
- 🔧 Flexible Configuration: Custom status codes and error codes
- 🏗️ Nested Error Support: Forward inner errors with preserved status codes
- 🎨 Custom Response Functions: Use custom functions for specialized error handling
- ⚡ Zero Runtime Cost: All code generation happens at compile time
Note: This is an experimental project. The API may change in future versions.
Installation
Add this to your Cargo.toml
:
[]
= "0.2.1"
= "0.8"
= "2.0"
= "1.0"
Usage Examples
Basic Error Responses
use AxumErrorResponse;
use Error;
Generates JSON responses like:
Nested Error Responses
Use #[response(nested)]
to delegate to inner error responses:
Custom Error Response Functions
For specialized error handling, use custom response functions:
use ;
use ;
// Custom response function
This allows you to return any response format (plain text, XML, custom JSON, etc.) instead of the standard JSON format.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Repository
Find this project on GitHub: axum-error-handler