See _examples/routing/http-wire-errors as well.
()
| 6 | |
| 7 | // See _examples/routing/http-wire-errors as well. |
| 8 | func main() { |
| 9 | app := iris.New() |
| 10 | |
| 11 | // Catch a specific error code. |
| 12 | app.OnErrorCode(iris.StatusInternalServerError, func(ctx iris.Context) { |
| 13 | ctx.HTML("Message: <b>" + ctx.Values().GetString("message") + "</b>") |
| 14 | }) |
| 15 | |
| 16 | // Catch all error codes [app.OnAnyErrorCode...] |
| 17 | |
| 18 | app.Get("/", func(ctx iris.Context) { |
| 19 | ctx.HTML(`Click <a href="/my500">here</a> to pretend an HTTP error`) |
| 20 | }) |
| 21 | |
| 22 | app.Get("/my500", func(ctx iris.Context) { |
| 23 | ctx.Values().Set("message", "this is the error message") |
| 24 | ctx.StatusCode(500) |
| 25 | }) |
| 26 | |
| 27 | app.Get("/u/{firstname:alphabetical}", func(ctx iris.Context) { |
| 28 | ctx.Writef("Hello %s", ctx.Params().Get("firstname")) |
| 29 | }) |
| 30 | |
| 31 | // Read more at: https://github.com/kataras/iris/issues/1335 |
| 32 | app.Get("/product-problem", problemExample) |
| 33 | |
| 34 | app.Get("/product-error", func(ctx iris.Context) { |
| 35 | ctx.Writef("explain the error") |
| 36 | }) |
| 37 | |
| 38 | // http://localhost:8080 |
| 39 | // http://localhost:8080/my500 |
| 40 | // http://localhost:8080/u/gerasimos |
| 41 | // http://localhost:8080/product-problem |
| 42 | app.Listen(":8080") |
| 43 | } |
| 44 | |
| 45 | func newProductProblem(productName, detail string) iris.Problem { |
| 46 | return iris.NewProblem(). |
nothing calls this directly
no test coverage detected
searching dependent graphs…