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:
parent
1ad63efb6c
commit
2d142b11c1
gerrit-server/src/main/java/com/google/gerrit/server
@ -126,7 +126,7 @@ class ChangeApiImpl extends ChangeApi.NotImplemented implements ChangeApi {
|
|||||||
try {
|
try {
|
||||||
return revisionApi.create(
|
return revisionApi.create(
|
||||||
revisions.parse(change, IdString.fromDecoded(id)));
|
revisions.parse(change, IdString.fromDecoded(id)));
|
||||||
} catch (OrmException e) {
|
} catch (OrmException | IOException e) {
|
||||||
throw new RestApiException("Cannot parse revision", e);
|
throw new RestApiException("Cannot parse revision", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,8 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RevisionResource parse(ChangeResource change, IdString id)
|
public RevisionResource parse(ChangeResource change, IdString id)
|
||||||
throws ResourceNotFoundException, OrmException {
|
throws ResourceNotFoundException, AuthException, OrmException,
|
||||||
|
IOException {
|
||||||
if (id.equals("current")) {
|
if (id.equals("current")) {
|
||||||
PatchSet.Id p = change.getChange().currentPatchSetId();
|
PatchSet.Id p = change.getChange().currentPatchSetId();
|
||||||
PatchSet ps = p != null ? dbProvider.get().patchSets().get(p) : null;
|
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)
|
private List<RevisionResource> find(ChangeResource change, String id)
|
||||||
throws OrmException {
|
throws OrmException, IOException, AuthException {
|
||||||
if (id.equals("0")) {
|
if (id.equals("0")) {
|
||||||
return loadEdit(change, null);
|
return loadEdit(change, null);
|
||||||
} else if (id.length() < 6 && id.matches("^[1-9][0-9]{0,4}$")) {
|
} 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)
|
private List<RevisionResource> loadEdit(ChangeResource change, RevId revid)
|
||||||
throws OrmException {
|
throws AuthException, IOException {
|
||||||
try {
|
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
|
||||||
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
|
if (edit.isPresent()) {
|
||||||
if (edit.isPresent()) {
|
PatchSet ps = new PatchSet(new PatchSet.Id(
|
||||||
PatchSet ps = new PatchSet(new PatchSet.Id(
|
change.getChange().getId(), 0));
|
||||||
change.getChange().getId(), 0));
|
ps.setRevision(edit.get().getRevision());
|
||||||
ps.setRevision(edit.get().getRevision());
|
if (revid == null || edit.get().getRevision().equals(revid)) {
|
||||||
if (revid == null || edit.get().getRevision().equals(revid)) {
|
return Collections.singletonList(
|
||||||
return Collections.singletonList(
|
new RevisionResource(change, ps, edit));
|
||||||
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,
|
private static List<RevisionResource> toResources(final ChangeResource change,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user