Update Set Review API to behave in line with RFC 7231

This CL updates the implementation of PostReview to replace
all instances of raising UnprocessableEntityException
(HTTP 422) with failed Additions instead. This matches the
docs for Set Reviewer, which no longer mention 422 being a
valid response code. This also falls in line with
RFC 7231, which promotes HTTP 400s with detailed bodies
over 422s.

It also updates the documentation to be clearer about
how these API functions work.

Bug: issue 6016
Change-Id: I1adad98107ba021132293ec47c6a6da01787556e
This commit is contained in:
Aaron Gable
2017-04-25 12:03:37 -07:00
committed by David Pursehouse
parent 0beb6d9540
commit 8c650215eb
9 changed files with 234 additions and 190 deletions

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.api.changes;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.changes.AbandonInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
import com.google.gerrit.extensions.api.changes.AssigneeInput;
import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.ChangeEditApi;
@@ -406,16 +407,16 @@ class ChangeApiImpl implements ChangeApi {
}
@Override
public void addReviewer(String reviewer) throws RestApiException {
public AddReviewerResult addReviewer(String reviewer) throws RestApiException {
AddReviewerInput in = new AddReviewerInput();
in.reviewer = reviewer;
addReviewer(in);
return addReviewer(in);
}
@Override
public void addReviewer(AddReviewerInput in) throws RestApiException {
public AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException {
try {
postReviewers.apply(change, in);
return postReviewers.apply(change, in);
} catch (OrmException | IOException | UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot add change reviewer", e);
}