iris/_examples/mvc/error-handler/main.go
Gerasimos (Makis) Maropoulos 3945fa68d1 obey the vote of @1370 (77-111 at this point) - add import suffix on iris repository
We have to do the same on iris-contrib/examples, iris-contrib/middleware and e.t.c.


Former-commit-id: 0860688158f374bc137bc934b81b26dcd0e10964
2019-10-25 01:27:02 +03:00

40 lines
828 B
Go

package main
import (
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/mvc"
)
func main() {
app := iris.New()
app.Logger().SetLevel("debug")
mvcApp := mvc.New(app)
// To all controllers, it can optionally be overridden per-controller
// if the controller contains the `HandleError(ctx iris.Context, err error)` function.
//
mvcApp.HandleError(func(ctx iris.Context, err error) {
ctx.HTML(fmt.Sprintf("<b>%s</b>", err.Error()))
})
//
mvcApp.Handle(new(myController))
// http://localhost:8080
app.Run(iris.Addr(":8080"))
}
type myController struct {
}
// overriddes the mvcApp.HandleError function.
func (c *myController) HandleError(ctx iris.Context, err error) {
ctx.HTML(fmt.Sprintf("<i>%s</i>", err.Error()))
}
func (c *myController) Get() error {
return fmt.Errorf("error here")
}