Fix exception handling when trying to parse an edit as anonymous user

Accessing a file in a change edit (http://host:8080/#/c/3/edit/test.txt)
as not signed in user failed with Internal Server Error, rather than
saying that the user must sign in.

Change-Id: I7f19e13e3f5663598daa0a4f63ca24a3f7eb844e
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2015-01-21 15:30:17 +01:00 committed by David Pursehouse
parent 1ad63efb6c
commit 2d142b11c1
2 changed files with 14 additions and 17 deletions
gerrit-server/src/main/java/com/google/gerrit/server

@ -126,7 +126,7 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
try {
return revisionApi.create(
revisions.parse(change, IdString.fromDecoded(id)));
} catch (OrmException e) {
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot parse revision", e);
}
}

@ -69,7 +69,8 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
@Override
public RevisionResource parse(ChangeResource change, IdString id)
throws ResourceNotFoundException, OrmException {
throws ResourceNotFoundException, AuthException, OrmException,
IOException {
if (id.equals("current")) {
PatchSet.Id p = change.getChange().currentPatchSetId();
PatchSet ps = p != null ? dbProvider.get().patchSets().get(p) : null;
@ -103,7 +104,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
}
private List<RevisionResource> find(ChangeResource change, String id)
throws OrmException {
throws OrmException, IOException, AuthException {
if (id.equals("0")) {
return loadEdit(change, null);
} else if (id.length() < 6 && id.matches("^[1-9][0-9]{0,4}$")) {
@ -157,22 +158,18 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
}
private List<RevisionResource> loadEdit(ChangeResource change, RevId revid)
throws OrmException {
try {
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
if (edit.isPresent()) {
PatchSet ps = new PatchSet(new PatchSet.Id(
change.getChange().getId(), 0));
ps.setRevision(edit.get().getRevision());
if (revid == null || edit.get().getRevision().equals(revid)) {
return Collections.singletonList(
new RevisionResource(change, ps, edit));
}
throws AuthException, IOException {
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
if (edit.isPresent()) {
PatchSet ps = new PatchSet(new PatchSet.Id(
change.getChange().getId(), 0));
ps.setRevision(edit.get().getRevision());
if (revid == null || edit.get().getRevision().equals(revid)) {
return Collections.singletonList(
new RevisionResource(change, ps, edit));
}
return Collections.emptyList();
} catch (AuthException | IOException e) {
throw new OrmException(e);
}
return Collections.emptyList();
}
private static List<RevisionResource> toResources(final ChangeResource change,