| 73 | } |
| 74 | |
| 75 | func 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 | } |