Skip to content

Commit 9c104b3

Browse files
pyrookapadamstx
authored andcommitted
fix: avoid runtime panic when the errors field of the response is nil
Signed-off-by: Norbert Biczo <pyrooka@users.noreply.github.com>
1 parent cac0b03 commit 9c104b3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

‎core/base_service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,11 @@ func getErrorMessage(responseMap map[string]interface{}, statusCode int) string
627627
var errors Errors
628628
responseBuffer, _ := json.Marshal(responseMap)
629629
if err := json.Unmarshal(responseBuffer, &errors); err == nil {
630-
return errors.Errors[0].Message
630+
if len(errors.Errors) > 0 {
631+
return errors.Errors[0].Message
632+
}
633+
634+
return ""
631635
}
632636
}
633637

‎core/base_service_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,8 @@ func TestErrorMessage(t *testing.T) {
21702170
testGetErrorMessage(t, http.StatusInternalServerError,
21712171
`{"errorMessage":{"statusCode":500,"message":"Internal Server Error"}}`,
21722172
"Internal Server Error")
2173+
2174+
testGetErrorMessage(t, http.StatusInternalServerError, `{"errors": null}`, "")
21732175
}
21742176

21752177
func getTLSVersion(service *BaseService) int {

0 commit comments

Comments
 (0)