Skip to content

Commit 8d23dde

Browse files
committed
Handle error if more than 1 sortField query parameter
1 parent c9f25bd commit 8d23dde

File tree

1 file changed

+6
-1
lines changed
  • services/question-service/handlers

1 file changed

+6
-1
lines changed

services/question-service/handlers/list.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ func (s *Service) ListQuestions(w http.ResponseWriter, r *http.Request) {
8181
return
8282
}
8383

84+
if len(sortFieldsParam) > 1 || len(sortValuesParam) > 1 {
85+
http.Error(w, "At most 1 sortField and sortValue pair allowed", http.StatusBadRequest)
86+
return
87+
}
88+
8489
sortedById := false
8590
for i, sortField := range sortFieldsParam {
8691
if !isValidSortField[sortField] {
@@ -108,7 +113,7 @@ func (s *Service) ListQuestions(w http.ResponseWriter, r *http.Request) {
108113
totalIter, err := query.Documents(ctx).GetAll()
109114
totalCount := len(totalIter)
110115
if err != nil {
111-
http.Error(w, "Failed to count questions", http.StatusInternalServerError)
116+
http.Error(w, "Failed to count questions: "+err.Error(), http.StatusInternalServerError)
112117
return
113118
}
114119

0 commit comments

Comments
 (0)