ChecksFactory: Do only throw RestApiException

All our extension API only throws RestApiExceptions, other exceptions
are always wrapped in RestApiException. Be consistent and do the same
here.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ia86238e32f2f07bd889ec7d5783486510fd96506
diff --git a/java/com/google/gerrit/plugins/checks/api/ChecksFactory.java b/java/com/google/gerrit/plugins/checks/api/ChecksFactory.java
index ecd26d8..e6ae0a1 100644
--- a/java/com/google/gerrit/plugins/checks/api/ChecksFactory.java
+++ b/java/com/google/gerrit/plugins/checks/api/ChecksFactory.java
@@ -14,6 +14,8 @@
 
 package com.google.gerrit.plugins.checks.api;
 
+import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
+
 import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
 import com.google.gerrit.extensions.restapi.RestApiException;
 import com.google.gerrit.reviewdb.client.Change;
@@ -24,7 +26,6 @@
 import com.google.gerrit.server.change.RevisionResource;
 import com.google.gerrit.server.notedb.ChangeNotes;
 import com.google.gerrit.server.project.NoSuchChangeException;
-import com.google.gwtorm.server.OrmException;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
@@ -52,25 +53,43 @@
     this.changeResourceFactory = changeResourceFactory;
   }
 
-  public Checks currentRevision(Change.Id changeId) throws OrmException, RestApiException {
+  public Checks currentRevision(Change.Id changeId) throws RestApiException {
     ChangeResource changeResource = getChangeResource(changeId);
-    PatchSet patchSet = psUtil.current(changeResource.getNotes());
+    PatchSet patchSet = getCurrentPatchSet(changeResource.getNotes());
     return getChecks(changeResource, patchSet);
   }
 
-  public Checks revision(PatchSet.Id patchSetId) throws OrmException, RestApiException {
+  public Checks revision(PatchSet.Id patchSetId) throws RestApiException {
     ChangeResource changeResource = getChangeResource(patchSetId.getParentKey());
-    PatchSet patchSet = psUtil.get(changeResource.getNotes(), patchSetId);
+    PatchSet patchSet = getPatchSet(changeResource.getNotes(), patchSetId);
     return getChecks(changeResource, patchSet);
   }
 
-  private ChangeResource getChangeResource(Change.Id changeId)
-      throws OrmException, RestApiException {
+  private ChangeResource getChangeResource(Change.Id changeId) throws RestApiException {
     try {
       ChangeNotes notes = changeNotesFactory.createChecked(changeId);
       return changeResourceFactory.create(notes, user.get());
     } catch (NoSuchChangeException e) {
       throw new ResourceNotFoundException(String.format("Change %d not found", changeId.get()), e);
+    } catch (Exception e) {
+      throw asRestApiException("Cannot retrieve change", e);
+    }
+  }
+
+  private PatchSet getCurrentPatchSet(ChangeNotes changeNotes) throws RestApiException {
+    try {
+      return psUtil.current(changeNotes);
+    } catch (Exception e) {
+      throw asRestApiException("Cannot retrieve current revision", e);
+    }
+  }
+
+  private PatchSet getPatchSet(ChangeNotes changeNotes, PatchSet.Id patchSetId)
+      throws RestApiException {
+    try {
+      return psUtil.get(changeNotes, patchSetId);
+    } catch (Exception e) {
+      throw asRestApiException("Cannot retrieve revision", e);
     }
   }
 
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java b/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java
index 6145e3c..e3fbbb3 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/api/GetCheckIT.java
@@ -44,7 +44,6 @@
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.testing.TestTimeUtil;
 import com.google.gson.reflect.TypeToken;
-import com.google.gwtorm.server.OrmException;
 import com.google.inject.Inject;
 import java.sql.Timestamp;
 import java.time.Instant;
@@ -528,7 +527,7 @@
 
   private CheckInfo getCheckInfo(
       PatchSet.Id patchSetId, CheckerUuid checkerUuid, ListChecksOption... options)
-      throws RestApiException, OrmException {
+      throws RestApiException {
     return checksApiFactory.revision(patchSetId).id(checkerUuid).get(options);
   }
 
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/CheckOperationsImplTest.java b/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/CheckOperationsImplTest.java
index 500daf8..54c0736 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/CheckOperationsImplTest.java
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/CheckOperationsImplTest.java
@@ -37,7 +37,6 @@
 import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.reviewdb.client.RevId;
 import com.google.gerrit.server.util.time.TimeUtil;
-import com.google.gwtorm.server.OrmException;
 import java.io.IOException;
 import java.sql.Timestamp;
 import java.util.Optional;
@@ -471,7 +470,7 @@
     assertThat(checkInfo.updated).isEqualTo(check.updated());
   }
 
-  private CheckInfo getCheckFromServer(CheckKey checkKey) throws RestApiException, OrmException {
+  private CheckInfo getCheckFromServer(CheckKey checkKey) throws RestApiException {
     return checksApiFactory.revision(checkKey.patchSet()).id(checkKey.checkerUuid()).get();
   }
 
@@ -486,7 +485,7 @@
 
   private CheckKey createCheckInServer(
       Project.NameKey repositoryName, PatchSet.Id patchSetId, CheckInput checkInput)
-      throws RestApiException, OrmException {
+      throws RestApiException {
     checksApiFactory.revision(patchSetId).create(checkInput);
     return CheckKey.create(repositoryName, patchSetId, CheckerUuid.parse(checkInput.checkerUuid));
   }