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

Function problemExample

_examples/routing/http-errors/main.go:61–117  ·  view source on GitHub ↗
(ctx iris.Context)

Source from the content-addressed store, hash-verified

59}
60
61func problemExample(ctx iris.Context) {
62 /*
63 p := iris.NewProblem().
64 Type("/validation-error").
65 Title("Your request parameters didn't validate").
66 Detail("Optional details about the error.").
67 Status(iris.StatusBadRequest).
68 Key("customField1", customValue1)
69 Key("customField2", customValue2)
70 ctx.Problem(p)
71
72 // OR
73 ctx.Problem(iris.Problem{
74 "type": "/validation-error",
75 "title": "Your request parameters didn't validate",
76 "detail": "Optional details about the error.",
77 "status": iris.StatusBadRequest,
78 "customField1": customValue1,
79 "customField2": customValue2,
80 })
81
82 // OR
83 */
84
85 // Response like JSON but with indent of " " and
86 // content type of "application/problem+json"
87 ctx.Problem(newProductProblem("product name", "problem error details"), iris.ProblemOptions{
88 // Optional JSON renderer settings.
89 JSON: iris.JSON{
90 Indent: " ",
91 },
92 // OR
93 // Render as XML:
94 //
95 // RenderXML: true,
96 // XML: iris.XML{Indent: " "},
97 // and ctx.StatusCode(200) to see the result on browser as a user.
98 //
99 // The below `RetryAfter` field sets the "Retry-After" response header.
100 //
101 // Can accept:
102 // time.Time for HTTP-Date,
103 // time.Duration, int64, float64, int for seconds
104 // or string for date or duration.
105 // Examples:
106 // time.Now().Add(5 * time.Minute),
107 // 300 * time.Second,
108 // "5m",
109 //
110 RetryAfter: 300,
111 // A function that, if specified, can dynamically set
112 // retry-after based on the request. Useful for ProblemOptions reusability.
113 // Overrides the RetryAfter field.
114 //
115 // RetryAfterFunc: func(iris.Context) interface{} { [...] }
116 })
117}

Callers

nothing calls this directly

Calls 2

newProductProblemFunction · 0.85
ProblemMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…