Skip to content

Commit 92c8a32

Browse files
authored
fix: Solve API not returning the expected error format (#170)
* fix: Solve API not returning the expected error format
1 parent 77a1ac2 commit 92c8a32

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

sysdig/internal/client/monitor/helpers.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ func errorFromResponse(response *http.Response) error {
1717
return errors.New(response.Status)
1818
}
1919

20-
search, err := jmespath.Search("[message, errors[].[reason, message]][][] | join(', ', @)", data)
20+
search, err := jmespath.Search("[error, message, errors[].[reason, message]][][] | join(', ', @)", data)
2121
if err != nil {
2222
return errors.New(response.Status)
2323
}
2424

2525
if searchArray, ok := search.([]interface{}); ok {
26-
return errors.New(strings.Join(cast.ToStringSlice(searchArray), ", "))
26+
errorString := strings.Join(cast.ToStringSlice(searchArray), ", ")
27+
if errorString == "" {
28+
return errors.New(response.Status)
29+
}
30+
return errors.New(errorString)
2731
}
2832

29-
return errors.New(cast.ToString(search))
33+
toString := cast.ToString(search)
34+
if toString == "" {
35+
return errors.New(response.Status)
36+
}
37+
return errors.New(toString)
3038
}

0 commit comments

Comments
 (0)