Error Handling
Manage how errors are returned to the client.
Handling Errors
You can return errors directly from your handlers. Routix comes with a standard error formatter.
r.GET("/item/:id", func(c *routix.Context) error {
item, err := findItem(c.Params["id"])
if err != nil {
return c.Error(404, "Item not found")
}
return c.JSON(200, item)
})Custom 404 Handler
You can override the default 404 Not Found response.
r.NotFound(func(c *routix.Context) error {
return c.JSON(404, map[string]string{
"error": "The endpoint you requested does not exist.",
})
})