ErrorName identifies the attribute of a custom error type used to select the returned error response when multiple errors of that type are defined on the same method. The value of the field identifies the error name as defined in the design. This makes it possible to define distinct transport mappin
(args ...any)
| 172 | // return nil |
| 173 | // } |
| 174 | func ErrorName(args ...any) { |
| 175 | if len(args) == 0 { |
| 176 | eval.TooFewArgError() |
| 177 | return |
| 178 | } |
| 179 | dsl, ok := args[len(args)-1].(func()) |
| 180 | if ok { |
| 181 | args[len(args)-1] = func() { |
| 182 | dsl() |
| 183 | Meta("struct:error:name") |
| 184 | } |
| 185 | } else { |
| 186 | args = append(args, func() { |
| 187 | Meta("struct:error:name") |
| 188 | }) |
| 189 | } |
| 190 | switch actual := args[0].(type) { |
| 191 | case string: |
| 192 | Attribute(actual, args[1:]...) |
| 193 | case int: |
| 194 | if len(args) == 2 { |
| 195 | eval.TooFewArgError() |
| 196 | return |
| 197 | } |
| 198 | name, ok := args[1].(string) |
| 199 | if !ok { |
| 200 | eval.InvalidArgError("name", args[1]) |
| 201 | return |
| 202 | } |
| 203 | Field(actual, name, args[2:]...) |
| 204 | default: |
| 205 | eval.InvalidArgError("name or position", args[0]) |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // Temporary qualifies an error type as describing temporary (i.e. retryable) |
| 210 | // errors. |