Kyrux
Back

Error Pages

Behavior per environment

Environment 404 / 4xx / 5xx Panic / Exception
production Styled error page 500 error page
development Debug page (with registered routes) Debug page (with stack trace)

The debug page is displayed automatically — there's no dedicated route. Any error or panic in development triggers it directly.

Triggering an error in a view

func PostView(ctx *router.Context) {
    post := models.Buscar(ctx.ParamInt("id"))
    if post == nil {
        ctx.Error(404)   // renders the 404 page
        return
    }
    // ...
}

Customizing an error page

import "kyrux/core/errors"

// In any init() or Register():
errors.Set(404, func(w http.ResponseWriter, r *http.Request) {
    // Render your own 404 template
    // or return JSON for APIs:
    w.Header().Set("Content-Type", "application/json")
    w.WriteHeader(404)
    json.NewEncoder(w).Encode(map[string]string{"error": "not found"})
})

errors.Set(500, func(w http.ResponseWriter, r *http.Request) {
    render.For("meuapp").Render(/* ... */)
})

Handlers registered via errors.Set() always take priority, in any environment.