Skip to content

Commit 36bcd93

Browse files
committed
upd to handle errors
1 parent 9b7f1e4 commit 36bcd93

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

cmd/gatewayPattern.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func GatewayPatternCmd(ctx *pkg.AppContext) *cobra.Command {
2727
Long: heredoc.Doc(`
2828
`),
2929
Example: heredoc.Doc(`
30-
$ gwa gateway-pattern
3130
$ gwa gateway-pattern path/to/config1.yaml
3231
`),
3332
RunE: pkg.WrapError(ctx, func(_ *cobra.Command, args []string) error {

pkg/api.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ func NewApiDelete[T any](ctx *AppContext, url string) (*NewApi[T], error) {
124124

125125
// API error parsing
126126
type ApiErrorResponse struct {
127-
Error string `json:"error"`
128-
ErrorMessage string `json:"error_description"`
129-
Message string `json:"message"`
130-
Results string `json:"results"`
127+
Error string `json:"error"`
128+
ErrorMessage string `json:"error_description"`
129+
Message string `json:"message"`
130+
Results string `json:"results"`
131+
Fields map[string]any `json:"fields"`
131132
Details struct {
132133
Item struct {
133134
Message string `json:"message"`
@@ -143,6 +144,11 @@ func (e *ApiErrorResponse) GetError() error {
143144
if e.Message != "" {
144145
result = append(result, e.Message)
145146
}
147+
if e.Fields != nil {
148+
for k, v := range e.Fields {
149+
result = append(result, fmt.Sprintf("%s: %s", k, v.(map[string]interface{})["message"].(string)))
150+
}
151+
}
146152
if e.Results != "" {
147153
result = append(result, e.Results)
148154
}

0 commit comments

Comments
 (0)