MCPcopy Index your code
hub / github.com/kataras/iris / fireErrorWithProblem

Function fireErrorWithProblem

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

Source from the content-addressed store, hash-verified

73}
74
75func fireErrorWithProblem(ctx iris.Context) {
76 myCondition := true
77 if myCondition {
78 problem := iris.NewProblem().
79 // The type URI, if relative it automatically convert to absolute.
80 Type("/product-error").
81 // The title, if empty then it gets it from the status code.
82 Title("Product validation problem").
83 // Any optional details.
84 Detail("details about the product error").
85 // The status error code of the problem, can be optional here.
86 // Status(iris.StatusBadRequest).
87 // Any custom key-value pair.
88 Key("product_name", "the product name")
89
90 errors.InvalidArgument.Data(ctx, "unable to process the request", problem)
91 return
92
93 /* Prints to the client:
94 {
95 "http_error_code": {
96 "canonical_name": "INVALID_ARGUMENT",
97 "status": 400
98 },
99 "message": "unable to process the request",
100 "data": {
101 "detail": "details about the product error",
102 "product_name": "the product name",
103 "title": "Product validation problem",
104 "type": "/product-error"
105 }
106 }
107 */
108 }
109
110}

Callers

nothing calls this directly

Calls 5

KeyMethod · 0.80
DetailMethod · 0.80
TitleMethod · 0.80
TypeMethod · 0.80
DataMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…