Skip to content
Snippets Groups Projects
Commit 62fa5edc authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Handle empty responses properly

parent 75ca05d7
No related merge requests found
......@@ -1007,13 +1007,13 @@ public class CouchDBDao implements IDatabaseDao {
@Override
public List<Answer> getFreetextAnswers(String questionId) {
try {
List<Answer> answers = new ArrayList<Answer>();
View view = new View("skill_question/freetext_answers_full");
view.setKey(URLEncoder.encode("\"" + questionId + "\"", "UTF-8"));
ViewResults results = this.getDatabase().view(view);
if (results.getResults().isEmpty()) {
throw new NotFoundException();
return answers;
}
List<Answer> answers = new ArrayList<Answer>();
for (Document d : results.getResults()) {
Answer a = (Answer) JSONObject.toBean(d.getJSONObject().getJSONObject("value"), Answer.class);
a.setQuestionId(questionId);
......
......@@ -229,7 +229,11 @@ public class QuestionService implements IQuestionService {
@Override
@Authenticated
public List<Answer> getFreetextAnswers(String questionId) {
return databaseDao.getFreetextAnswers(questionId);
List<Answer> answers = databaseDao.getFreetextAnswers(questionId);
if (answers == null) {
throw new NotFoundException();
}
return answers;
}
@Override
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment