Return '404 Not Found' on delete of a non-existing change edit
The current response code '400 Bad Request' is wrong as this indicates a request that is not understood by the server due to malformed syntax. In this case the request is syntactically correct but the resource doesn't exist, hence '404 Not Found' is the correct response. Change-Id: I13a2ab76150709886141672bc5fe9534a40a8d40 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
committed by
Dave Borowitz
parent
e3a82235bf
commit
bb04b0d2b6
@@ -17,7 +17,7 @@ package com.google.gerrit.acceptance.edit;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.apache.http.HttpStatus.SC_BAD_REQUEST;
|
||||
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
|
||||
import static org.apache.http.HttpStatus.SC_NO_CONTENT;
|
||||
import static org.apache.http.HttpStatus.SC_OK;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
@@ -373,7 +373,7 @@ public class ChangeEditIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void deletingNonExistingEditRest() throws Exception {
|
||||
RestResponse r = session.delete(urlEdit());
|
||||
assertEquals(SC_BAD_REQUEST, r.getStatusCode());
|
||||
assertEquals(SC_NOT_FOUND, r.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||
import com.google.gerrit.server.change.DeleteChangeEdit.Input;
|
||||
@@ -42,13 +42,13 @@ public class DeleteChangeEdit implements RestModifyView<ChangeResource, Input> {
|
||||
|
||||
@Override
|
||||
public Response<?> apply(ChangeResource rsrc, Input input)
|
||||
throws AuthException, BadRequestException, IOException,
|
||||
throws AuthException, ResourceNotFoundException, IOException,
|
||||
InvalidChangeOperationException {
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getChange());
|
||||
if (edit.isPresent()) {
|
||||
editUtil.delete(edit.get());
|
||||
} else {
|
||||
throw new BadRequestException("change edit doesn't exist");
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
return Response.none();
|
||||
|
||||
Reference in New Issue
Block a user