The Error Handler Library provides a centralized solution for managing errors in Go applications. Its primary purpose is to streamline error handling across various frameworks, ensuring that developers can focus on building features rather than managing error states.
- Centralized error handling
- Automatic database error detection
- Panic recovery
go get github.com/emreisler/error-handlerimport "github.com/emreisler/error-handler"
func main() {
r := gin.Default()
r.Use(error_handler.GinMiddleware())
// Your routes here
}import "github.com/emreisler/error-handler"
func main() {
http.Handle("/", error_handler.NetHTTPMiddleware(http.HandlerFunc(yourHandler)))
http.ListenAndServe(":8080", nil)
}import "github.com/emreisler/error-handler"
func main() {
r := chi.NewRouter()
r.Use(error_handler.ChiMiddleware())
// Your routes here
}import "github.com/emreisler/error-handler"
func main() {
app := fiber.New()
app.Use(error_handler.FiberMiddleware())
// Your routes here
}The mapDBError function automatically maps database errors to a standardized error type, allowing for consistent error responses.
The library includes built-in panic recovery to prevent application crashes due to unexpected errors.
The library provides a mechanism for mapping different error types to a unified structure, making it easier to handle errors across various components.
We welcome contributions! Please submit a pull request or open an issue for any enhancements or bug fixes.
This library is licensed under the MIT License. See the LICENSE file for more details.