MCPcopy Create free account
hub / github.com/kataras/iris / main

Function main

_examples/routing/http-errors/main.go:8–43  ·  view source on GitHub ↗

See _examples/routing/http-wire-errors as well.

()

Source from the content-addressed store, hash-verified

6
7// See _examples/routing/http-wire-errors as well.
8func 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
45func newProductProblem(productName, detail string) iris.Problem {
46 return iris.NewProblem().

Callers

nothing calls this directly

Calls 11

NewMethod · 0.80
WritefMethod · 0.80
ParamsMethod · 0.80
OnErrorCodeMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65
StatusCodeMethod · 0.65
ListenMethod · 0.65
HTMLMethod · 0.45
GetStringMethod · 0.45
ValuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…