Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid runtime panic when the errors field is nil #236

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/base_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ func getErrorMessage(responseMap map[string]interface{}, statusCode int) string
var errors Errors
responseBuffer, _ := json.Marshal(responseMap)
if err := json.Unmarshal(responseBuffer, &errors); err == nil {
return errors.Errors[0].Message
if len(errors.Errors) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, how did we exist for so long with this bug in place? LOL
This must be the first time that a service returned an error response with an explicit null value for "errors".

Please check the other cores to make sure we don't have a similar bug there.

return errors.Errors[0].Message
}

return ""
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/base_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,8 @@ func TestErrorMessage(t *testing.T) {
testGetErrorMessage(t, http.StatusInternalServerError,
`{"errorMessage":{"statusCode":500,"message":"Internal Server Error"}}`,
"Internal Server Error")

testGetErrorMessage(t, http.StatusInternalServerError, `{"errors": null}`, "")
}

func getTLSVersion(service *BaseService) int {
Expand Down
Loading