Revert: Simplify exception handling
* revert method now throws ResourceNotFoundException instead of NoSuchChangeException which was then converted into ResourceNotFoundException later * unneeded throws declarations are removed from signature of revert method Change-Id: I9e91e33ce9ecd4b18c8617229347873ff6335106 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -50,8 +50,6 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
|
|
||||||
import org.eclipse.jgit.errors.MissingObjectException;
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
import org.eclipse.jgit.lib.CommitBuilder;
|
import org.eclipse.jgit.lib.CommitBuilder;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
@@ -122,26 +120,19 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
|
|||||||
throw new ResourceConflictException("change is " + status(change));
|
throw new ResourceConflictException("change is " + status(change));
|
||||||
}
|
}
|
||||||
|
|
||||||
Change.Id revertedChangeId;
|
Change.Id revertedChangeId =
|
||||||
try {
|
revert(req.getControl(), Strings.emptyToNull(input.message));
|
||||||
revertedChangeId = revert(req.getControl(),
|
|
||||||
Strings.emptyToNull(input.message));
|
|
||||||
} catch (NoSuchChangeException e) {
|
|
||||||
throw new ResourceNotFoundException(e.getMessage());
|
|
||||||
}
|
|
||||||
return json.create(ChangeJson.NO_OPTIONS).format(req.getProject(),
|
return json.create(ChangeJson.NO_OPTIONS).format(req.getProject(),
|
||||||
revertedChangeId);
|
revertedChangeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Change.Id revert(ChangeControl ctl, String message)
|
private Change.Id revert(ChangeControl ctl, String message)
|
||||||
throws NoSuchChangeException, OrmException, MissingObjectException,
|
throws OrmException, IOException, RestApiException, UpdateException {
|
||||||
IncorrectObjectTypeException, IOException, RestApiException,
|
|
||||||
UpdateException {
|
|
||||||
Change.Id changeIdToRevert = ctl.getChange().getId();
|
Change.Id changeIdToRevert = ctl.getChange().getId();
|
||||||
PatchSet.Id patchSetId = ctl.getChange().currentPatchSetId();
|
PatchSet.Id patchSetId = ctl.getChange().currentPatchSetId();
|
||||||
PatchSet patch = psUtil.get(db.get(), ctl.getNotes(), patchSetId);
|
PatchSet patch = psUtil.get(db.get(), ctl.getNotes(), patchSetId);
|
||||||
if (patch == null) {
|
if (patch == null) {
|
||||||
throw new NoSuchChangeException(changeIdToRevert);
|
throw new ResourceNotFoundException(changeIdToRevert.toString());
|
||||||
}
|
}
|
||||||
Change changeToRevert = db.get().changes().get(changeIdToRevert);
|
Change changeToRevert = db.get().changes().get(changeIdToRevert);
|
||||||
|
|
||||||
@@ -228,7 +219,7 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
|
|||||||
|
|
||||||
return changeId;
|
return changeId;
|
||||||
} catch (RepositoryNotFoundException e) {
|
} catch (RepositoryNotFoundException e) {
|
||||||
throw new NoSuchChangeException(changeIdToRevert, e);
|
throw new ResourceNotFoundException(changeIdToRevert.toString(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user