Add static util for throwing exceptions from API implementations

This allows us to replace an arbitrarily long multi-catch clause with an
identical "catch Exception" clause in all API handlers, without having
to think about it. It also means that we can properly handle RestView
implementations that throw Exception from their apply methods, which is
allowed by RestView but not currently done in practice.

In the process, fix some places in TagApiImpl that were improperly
leaking an internal exception message from IOException to users.

Change-Id: If0d57be6774658a8c2a015fc5745390c1c2801d4
This commit is contained in:
Dave Borowitz
2017-05-04 12:48:31 -04:00
parent c0ba40f6c9
commit 5b9e7a8d25
21 changed files with 430 additions and 430 deletions

View File

@@ -0,0 +1,39 @@
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.api;
import com.google.common.base.Throwables;
import com.google.gerrit.extensions.restapi.RestApiException;
/** Static utilities for API implementations. */
public class ApiUtil {
/**
* Convert an exception encountered during API execution to a {@link RestApiException}.
*
* @param msg message to be used in the case where a new {@code RestApiException} is wrapped
* around {@code e}.
* @param e exception being handled.
* @return {@code e} if it is already a {@code RestApiException}, otherwise a new {@code
* RestApiException} wrapped around {@code e}.
* @throws RuntimeException if {@code e} is a runtime exception, it is rethrown as-is.
*/
public static RestApiException asRestApiException(String msg, Exception e)
throws RuntimeException {
Throwables.throwIfUnchecked(e);
return e instanceof RestApiException ? (RestApiException) e : new RestApiException(msg, e);
}
private ApiUtil() {}
}

View File

@@ -14,10 +14,10 @@
package com.google.gerrit.server.api.accounts;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import com.google.gerrit.common.RawInputUtil;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.accounts.AccountApi;
import com.google.gerrit.extensions.api.accounts.EmailInput;
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
@@ -38,7 +38,6 @@ import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.server.GpgException;
import com.google.gerrit.server.account.AccountLoader;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.account.AddSshKey;
@@ -71,15 +70,11 @@ import com.google.gerrit.server.account.StarredChanges;
import com.google.gerrit.server.account.Stars;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.ChangesCollection;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import org.eclipse.jgit.errors.ConfigInvalidException;
public class AccountApiImpl implements AccountApi {
interface Factory {
@@ -203,8 +198,8 @@ public class AccountApiImpl implements AccountApi {
AccountInfo ai = accountLoader.get(account.getUser().getAccountId());
accountLoader.fill();
return ai;
} catch (OrmException e) {
throw new RestApiException("Cannot parse change", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse change", e);
}
}
@@ -222,8 +217,8 @@ public class AccountApiImpl implements AccountApi {
} else {
deleteActive.apply(account, new DeleteActive.Input());
}
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot set active", e);
} catch (Exception e) {
throw asRestApiException("Cannot set active", e);
}
}
@@ -237,8 +232,8 @@ public class AccountApiImpl implements AccountApi {
public GeneralPreferencesInfo getPreferences() throws RestApiException {
try {
return getPreferences.apply(account);
} catch (PermissionBackendException e) {
throw new RestApiException("Cannot get preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot get preferences", e);
}
}
@@ -246,8 +241,8 @@ public class AccountApiImpl implements AccountApi {
public GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in) throws RestApiException {
try {
return setPreferences.apply(account, in);
} catch (IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot set preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot set preferences", e);
}
}
@@ -255,8 +250,8 @@ public class AccountApiImpl implements AccountApi {
public DiffPreferencesInfo getDiffPreferences() throws RestApiException {
try {
return getDiffPreferences.apply(account);
} catch (IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot query diff preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot query diff preferences", e);
}
}
@@ -264,8 +259,8 @@ public class AccountApiImpl implements AccountApi {
public DiffPreferencesInfo setDiffPreferences(DiffPreferencesInfo in) throws RestApiException {
try {
return setDiffPreferences.apply(account, in);
} catch (IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot set diff preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot set diff preferences", e);
}
}
@@ -273,8 +268,8 @@ public class AccountApiImpl implements AccountApi {
public EditPreferencesInfo getEditPreferences() throws RestApiException {
try {
return getEditPreferences.apply(account);
} catch (IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot query edit preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot query edit preferences", e);
}
}
@@ -282,8 +277,8 @@ public class AccountApiImpl implements AccountApi {
public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in) throws RestApiException {
try {
return setEditPreferences.apply(account, in);
} catch (IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot set edit preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot set edit preferences", e);
}
}
@@ -291,8 +286,8 @@ public class AccountApiImpl implements AccountApi {
public List<ProjectWatchInfo> getWatchedProjects() throws RestApiException {
try {
return getWatchedProjects.apply(account);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot get watched projects", e);
} catch (Exception e) {
throw asRestApiException("Cannot get watched projects", e);
}
}
@@ -301,8 +296,8 @@ public class AccountApiImpl implements AccountApi {
throws RestApiException {
try {
return postWatchedProjects.apply(account, in);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot update watched projects", e);
} catch (Exception e) {
throw asRestApiException("Cannot update watched projects", e);
}
}
@@ -310,8 +305,8 @@ public class AccountApiImpl implements AccountApi {
public void deleteWatchedProjects(List<ProjectWatchInfo> in) throws RestApiException {
try {
deleteWatchedProjects.apply(account, in);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot delete watched projects", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete watched projects", e);
}
}
@@ -321,8 +316,8 @@ public class AccountApiImpl implements AccountApi {
ChangeResource rsrc = changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId));
starredChangesCreate.setChange(rsrc);
starredChangesCreate.apply(account, new StarredChanges.EmptyInput());
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot star change", e);
} catch (Exception e) {
throw asRestApiException("Cannot star change", e);
}
}
@@ -333,8 +328,8 @@ public class AccountApiImpl implements AccountApi {
AccountResource.StarredChange starredChange =
new AccountResource.StarredChange(account.getUser(), rsrc);
starredChangesDelete.apply(starredChange, new StarredChanges.EmptyInput());
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot unstar change", e);
} catch (Exception e) {
throw asRestApiException("Cannot unstar change", e);
}
}
@@ -343,8 +338,8 @@ public class AccountApiImpl implements AccountApi {
try {
AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId));
starsPost.apply(rsrc, input);
} catch (OrmException e) {
throw new RestApiException("Cannot post stars", e);
} catch (Exception e) {
throw asRestApiException("Cannot post stars", e);
}
}
@@ -353,8 +348,8 @@ public class AccountApiImpl implements AccountApi {
try {
AccountResource.Star rsrc = stars.parse(account, IdString.fromUrl(changeId));
return starsGet.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot get stars", e);
} catch (Exception e) {
throw asRestApiException("Cannot get stars", e);
}
}
@@ -362,8 +357,8 @@ public class AccountApiImpl implements AccountApi {
public List<ChangeInfo> getStarredChanges() throws RestApiException {
try {
return stars.list().apply(account);
} catch (OrmException e) {
throw new RestApiException("Cannot get starred changes", e);
} catch (Exception e) {
throw asRestApiException("Cannot get starred changes", e);
}
}
@@ -377,12 +372,8 @@ public class AccountApiImpl implements AccountApi {
AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), input.email);
try {
createEmailFactory.create(input.email).apply(rsrc, input);
} catch (EmailException
| OrmException
| IOException
| ConfigInvalidException
| PermissionBackendException e) {
throw new RestApiException("Cannot add email", e);
} catch (Exception e) {
throw asRestApiException("Cannot add email", e);
}
}
@@ -391,8 +382,8 @@ public class AccountApiImpl implements AccountApi {
AccountResource.Email rsrc = new AccountResource.Email(account.getUser(), email);
try {
deleteEmail.apply(rsrc, null);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot delete email", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete email", e);
}
}
@@ -401,8 +392,8 @@ public class AccountApiImpl implements AccountApi {
PutStatus.Input in = new PutStatus.Input(status);
try {
putStatus.apply(account, in);
} catch (OrmException | IOException | PermissionBackendException e) {
throw new RestApiException("Cannot set status", e);
} catch (Exception e) {
throw asRestApiException("Cannot set status", e);
}
}
@@ -410,8 +401,8 @@ public class AccountApiImpl implements AccountApi {
public List<SshKeyInfo> listSshKeys() throws RestApiException {
try {
return getSshKeys.apply(account);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot list SSH keys", e);
} catch (Exception e) {
throw asRestApiException("Cannot list SSH keys", e);
}
}
@@ -421,8 +412,8 @@ public class AccountApiImpl implements AccountApi {
in.raw = RawInputUtil.create(key);
try {
return addSshKey.apply(account, in).value();
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot add SSH key", e);
} catch (Exception e) {
throw asRestApiException("Cannot add SSH key", e);
}
}
@@ -432,8 +423,8 @@ public class AccountApiImpl implements AccountApi {
AccountResource.SshKey sshKeyRes =
sshKeys.parse(account, IdString.fromDecoded(Integer.toString(seq)));
deleteSshKey.apply(sshKeyRes, null);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot delete SSH key", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete SSH key", e);
}
}
@@ -441,8 +432,8 @@ public class AccountApiImpl implements AccountApi {
public Map<String, GpgKeyInfo> listGpgKeys() throws RestApiException {
try {
return gpgApiAdapter.listGpgKeys(account);
} catch (GpgException e) {
throw new RestApiException("Cannot list GPG keys", e);
} catch (Exception e) {
throw asRestApiException("Cannot list GPG keys", e);
}
}
@@ -451,8 +442,8 @@ public class AccountApiImpl implements AccountApi {
throws RestApiException {
try {
return gpgApiAdapter.putGpgKeys(account, add, delete);
} catch (GpgException e) {
throw new RestApiException("Cannot add GPG key", e);
} catch (Exception e) {
throw asRestApiException("Cannot add GPG key", e);
}
}
@@ -460,8 +451,8 @@ public class AccountApiImpl implements AccountApi {
public GpgKeyApi gpgKey(String id) throws RestApiException {
try {
return gpgApiAdapter.gpgKey(account, IdString.fromDecoded(id));
} catch (GpgException e) {
throw new RestApiException("Cannot get PGP key", e);
} catch (Exception e) {
throw asRestApiException("Cannot get PGP key", e);
}
}
@@ -476,8 +467,8 @@ public class AccountApiImpl implements AccountApi {
AgreementInput input = new AgreementInput();
input.name = agreementName;
putAgreement.apply(account, input);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot sign agreement", e);
} catch (Exception e) {
throw asRestApiException("Cannot sign agreement", e);
}
}
@@ -485,8 +476,8 @@ public class AccountApiImpl implements AccountApi {
public void index() throws RestApiException {
try {
index.apply(account, new Index.Input());
} catch (IOException | PermissionBackendException e) {
throw new RestApiException("Cannot index account", e);
} catch (Exception e) {
throw asRestApiException("Cannot index account", e);
}
}
@@ -494,8 +485,8 @@ public class AccountApiImpl implements AccountApi {
public List<AccountExternalIdInfo> getExternalIds() throws RestApiException {
try {
return getExternalIds.apply(account);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot get external IDs", e);
} catch (Exception e) {
throw asRestApiException("Cannot get external IDs", e);
}
}
@@ -503,8 +494,8 @@ public class AccountApiImpl implements AccountApi {
public void deleteExternalIds(List<String> externalIds) throws RestApiException {
try {
deleteExternalIds.apply(account, externalIds);
} catch (IOException | OrmException | ConfigInvalidException e) {
throw new RestApiException("Cannot delete external IDs", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete external IDs", e);
}
}
}

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.api.accounts;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.accounts.AccountApi;
import com.google.gerrit.extensions.api.accounts.AccountInput;
@@ -33,14 +34,10 @@ import com.google.gerrit.server.account.CreateAccount;
import com.google.gerrit.server.account.QueryAccounts;
import com.google.gerrit.server.permissions.GlobalPermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
public class AccountsImpl implements Accounts {
@@ -71,8 +68,8 @@ public class AccountsImpl implements Accounts {
public AccountApi id(String id) throws RestApiException {
try {
return api.create(accounts.parse(TopLevelResource.INSTANCE, IdString.fromDecoded(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot parse change", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse change", e);
}
}
@@ -106,8 +103,8 @@ public class AccountsImpl implements Accounts {
permissionBackend.user(self).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
AccountInfo info = impl.apply(TopLevelResource.INSTANCE, in).value();
return id(info._accountId);
} catch (OrmException | IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot create account " + in.username, e);
} catch (Exception e) {
throw asRestApiException("Cannot create account " + in.username, e);
}
}
@@ -133,8 +130,8 @@ public class AccountsImpl implements Accounts {
myQueryAccounts.setQuery(r.getQuery());
myQueryAccounts.setLimit(r.getLimit());
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve suggested accounts", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve suggested accounts", e);
}
}
@@ -163,8 +160,8 @@ public class AccountsImpl implements Accounts {
myQueryAccounts.addOption(option);
}
return myQueryAccounts.apply(TopLevelResource.INSTANCE);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve suggested accounts", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve suggested accounts", e);
}
}
}

View File

@@ -14,7 +14,8 @@
package com.google.gerrit.server.api.changes;
import com.google.gerrit.common.errors.EmailException;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.AbandonInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
@@ -82,14 +83,9 @@ import com.google.gerrit.server.change.SuggestChangeReviewers;
import com.google.gerrit.server.change.Unignore;
import com.google.gerrit.server.change.Unmute;
import com.google.gerrit.server.change.WorkInProgressOp;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
@@ -247,8 +243,8 @@ class ChangeApiImpl implements ChangeApi {
public RevisionApi revision(String id) throws RestApiException {
try {
return revisionApi.create(revisions.parse(change, IdString.fromDecoded(id)));
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot parse revision", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse revision", e);
}
}
@@ -256,8 +252,8 @@ class ChangeApiImpl implements ChangeApi {
public ReviewerApi reviewer(String id) throws RestApiException {
try {
return reviewerApi.create(reviewers.parse(change, IdString.fromDecoded(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot parse reviewer", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse reviewer", e);
}
}
@@ -270,8 +266,8 @@ class ChangeApiImpl implements ChangeApi {
public void abandon(AbandonInput in) throws RestApiException {
try {
abandon.apply(change, in);
} catch (OrmException | UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot abandon change", e);
} catch (Exception e) {
throw asRestApiException("Cannot abandon change", e);
}
}
@@ -284,8 +280,8 @@ class ChangeApiImpl implements ChangeApi {
public void restore(RestoreInput in) throws RestApiException {
try {
restore.apply(change, in);
} catch (OrmException | UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot restore change", e);
} catch (Exception e) {
throw asRestApiException("Cannot restore change", e);
}
}
@@ -300,8 +296,8 @@ class ChangeApiImpl implements ChangeApi {
public void move(MoveInput in) throws RestApiException {
try {
move.apply(change, in);
} catch (OrmException | UpdateException e) {
throw new RestApiException("Cannot move change", e);
} catch (Exception e) {
throw asRestApiException("Cannot move change", e);
}
}
@@ -313,8 +309,8 @@ class ChangeApiImpl implements ChangeApi {
} else {
deletePrivate.apply(change, null);
}
} catch (UpdateException e) {
throw new RestApiException("Cannot change private status", e);
} catch (Exception e) {
throw asRestApiException("Cannot change private status", e);
}
}
@@ -322,8 +318,8 @@ class ChangeApiImpl implements ChangeApi {
public void setWorkInProgress(String message) throws RestApiException {
try {
setWip.apply(change, new WorkInProgressOp.Input(message));
} catch (UpdateException e) {
throw new RestApiException("Cannot set work in progress state", e);
} catch (Exception e) {
throw asRestApiException("Cannot set work in progress state", e);
}
}
@@ -331,8 +327,8 @@ class ChangeApiImpl implements ChangeApi {
public void setReadyForReview(String message) throws RestApiException {
try {
setReady.apply(change, new WorkInProgressOp.Input(message));
} catch (UpdateException e) {
throw new RestApiException("Cannot set ready for review state", e);
} catch (Exception e) {
throw asRestApiException("Cannot set ready for review state", e);
}
}
@@ -345,8 +341,8 @@ class ChangeApiImpl implements ChangeApi {
public ChangeApi revert(RevertInput in) throws RestApiException {
try {
return changeApi.id(revert.apply(change, in)._number);
} catch (OrmException | IOException | UpdateException e) {
throw new RestApiException("Cannot revert change", e);
} catch (Exception e) {
throw asRestApiException("Cannot revert change", e);
}
}
@@ -354,8 +350,8 @@ class ChangeApiImpl implements ChangeApi {
public ChangeInfo createMergePatchSet(MergePatchSetInput in) throws RestApiException {
try {
return updateByMerge.apply(change, in).value();
} catch (IOException | UpdateException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot update change by merge", e);
} catch (Exception e) {
throw asRestApiException("Cannot update change by merge", e);
}
}
@@ -383,8 +379,8 @@ class ChangeApiImpl implements ChangeApi {
.addListChangesOption(listOptions)
.addSubmittedTogetherOption(submitOptions)
.applyInfo(change);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot query submittedTogether", e);
} catch (Exception e) {
throw asRestApiException("Cannot query submittedTogether", e);
}
}
@@ -392,8 +388,8 @@ class ChangeApiImpl implements ChangeApi {
public void publish() throws RestApiException {
try {
publishDraftChange.apply(change, null);
} catch (UpdateException e) {
throw new RestApiException("Cannot publish change", e);
} catch (Exception e) {
throw asRestApiException("Cannot publish change", e);
}
}
@@ -406,12 +402,8 @@ class ChangeApiImpl implements ChangeApi {
public void rebase(RebaseInput in) throws RestApiException {
try {
rebase.apply(change, in);
} catch (EmailException
| OrmException
| UpdateException
| IOException
| PermissionBackendException e) {
throw new RestApiException("Cannot rebase change", e);
} catch (Exception e) {
throw asRestApiException("Cannot rebase change", e);
}
}
@@ -419,8 +411,8 @@ class ChangeApiImpl implements ChangeApi {
public void delete() throws RestApiException {
try {
deleteChange.apply(change, null);
} catch (UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot delete change", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete change", e);
}
}
@@ -435,8 +427,8 @@ class ChangeApiImpl implements ChangeApi {
in.topic = topic;
try {
putTopic.apply(change, in);
} catch (UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot set topic", e);
} catch (Exception e) {
throw asRestApiException("Cannot set topic", e);
}
}
@@ -444,8 +436,8 @@ class ChangeApiImpl implements ChangeApi {
public IncludedInInfo includedIn() throws RestApiException {
try {
return includedIn.apply(change);
} catch (OrmException | IOException e) {
throw new RestApiException("Could not extract IncludedIn data", e);
} catch (Exception e) {
throw asRestApiException("Could not extract IncludedIn data", e);
}
}
@@ -460,8 +452,8 @@ class ChangeApiImpl implements ChangeApi {
public AddReviewerResult addReviewer(AddReviewerInput in) throws RestApiException {
try {
return postReviewers.apply(change, in);
} catch (OrmException | IOException | UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot add change reviewer", e);
} catch (Exception e) {
throw asRestApiException("Cannot add change reviewer", e);
}
}
@@ -486,8 +478,8 @@ class ChangeApiImpl implements ChangeApi {
suggestReviewers.setQuery(r.getQuery());
suggestReviewers.setLimit(r.getLimit());
return suggestReviewers.apply(change);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot retrieve suggested reviewers", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve suggested reviewers", e);
}
}
@@ -495,8 +487,8 @@ class ChangeApiImpl implements ChangeApi {
public ChangeInfo get(EnumSet<ListChangesOption> s) throws RestApiException {
try {
return changeJson.create(s).format(change);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve change", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve change", e);
}
}
@@ -524,8 +516,8 @@ class ChangeApiImpl implements ChangeApi {
public void setHashtags(HashtagsInput input) throws RestApiException {
try {
postHashtags.apply(change, input);
} catch (UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot post hashtags", e);
} catch (Exception e) {
throw asRestApiException("Cannot post hashtags", e);
}
}
@@ -533,8 +525,8 @@ class ChangeApiImpl implements ChangeApi {
public Set<String> getHashtags() throws RestApiException {
try {
return getHashtags.apply(change).value();
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot get hashtags", e);
} catch (Exception e) {
throw asRestApiException("Cannot get hashtags", e);
}
}
@@ -542,8 +534,8 @@ class ChangeApiImpl implements ChangeApi {
public AccountInfo setAssignee(AssigneeInput input) throws RestApiException {
try {
return putAssignee.apply(change, input);
} catch (UpdateException | IOException | OrmException | PermissionBackendException e) {
throw new RestApiException("Cannot set assignee", e);
} catch (Exception e) {
throw asRestApiException("Cannot set assignee", e);
}
}
@@ -552,8 +544,8 @@ class ChangeApiImpl implements ChangeApi {
try {
Response<AccountInfo> r = getAssignee.apply(change);
return r.isNone() ? null : r.value();
} catch (OrmException e) {
throw new RestApiException("Cannot get assignee", e);
} catch (Exception e) {
throw asRestApiException("Cannot get assignee", e);
}
}
@@ -561,8 +553,8 @@ class ChangeApiImpl implements ChangeApi {
public List<AccountInfo> getPastAssignees() throws RestApiException {
try {
return getPastAssignees.apply(change).value();
} catch (OrmException e) {
throw new RestApiException("Cannot get past assignees", e);
} catch (Exception e) {
throw asRestApiException("Cannot get past assignees", e);
}
}
@@ -571,8 +563,8 @@ class ChangeApiImpl implements ChangeApi {
try {
Response<AccountInfo> r = deleteAssignee.apply(change, null);
return r.isNone() ? null : r.value();
} catch (UpdateException | OrmException | PermissionBackendException e) {
throw new RestApiException("Cannot delete assignee", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete assignee", e);
}
}
@@ -580,8 +572,8 @@ class ChangeApiImpl implements ChangeApi {
public Map<String, List<CommentInfo>> comments() throws RestApiException {
try {
return listComments.apply(change);
} catch (OrmException e) {
throw new RestApiException("Cannot get comments", e);
} catch (Exception e) {
throw asRestApiException("Cannot get comments", e);
}
}
@@ -589,8 +581,8 @@ class ChangeApiImpl implements ChangeApi {
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
try {
return listChangeRobotComments.apply(change);
} catch (OrmException e) {
throw new RestApiException("Cannot get robot comments", e);
} catch (Exception e) {
throw asRestApiException("Cannot get robot comments", e);
}
}
@@ -598,8 +590,8 @@ class ChangeApiImpl implements ChangeApi {
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
try {
return listDrafts.apply(change);
} catch (OrmException e) {
throw new RestApiException("Cannot get drafts", e);
} catch (Exception e) {
throw asRestApiException("Cannot get drafts", e);
}
}
@@ -607,8 +599,8 @@ class ChangeApiImpl implements ChangeApi {
public ChangeInfo check() throws RestApiException {
try {
return check.apply(change).value();
} catch (OrmException e) {
throw new RestApiException("Cannot check change", e);
} catch (Exception e) {
throw asRestApiException("Cannot check change", e);
}
}
@@ -616,8 +608,8 @@ class ChangeApiImpl implements ChangeApi {
public ChangeInfo check(FixInput fix) throws RestApiException {
try {
return check.apply(change, fix).value();
} catch (OrmException | PermissionBackendException e) {
throw new RestApiException("Cannot check change", e);
} catch (Exception e) {
throw asRestApiException("Cannot check change", e);
}
}
@@ -625,8 +617,8 @@ class ChangeApiImpl implements ChangeApi {
public void index() throws RestApiException {
try {
index.apply(change, new Index.Input());
} catch (IOException | OrmException | PermissionBackendException e) {
throw new RestApiException("Cannot index change", e);
} catch (Exception e) {
throw asRestApiException("Cannot index change", e);
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.ChangeEditApi;
import com.google.gerrit.extensions.api.changes.PublishChangeEditInput;
import com.google.gerrit.extensions.common.EditInfo;
@@ -30,7 +32,6 @@ import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.DeleteChangeEdit;
import com.google.gerrit.server.change.PublishChangeEdit;
import com.google.gerrit.server.change.RebaseChangeEdit;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -88,8 +89,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
try {
Response<EditInfo> edit = editDetail.apply(changeResource);
return edit.isNone() ? Optional.empty() : Optional.of(edit.value());
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot retrieve change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve change edit", e);
}
}
@@ -97,8 +98,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
public void create() throws RestApiException {
try {
changeEditsPost.apply(changeResource, null);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot create change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot create change edit", e);
}
}
@@ -106,8 +107,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
public void delete() throws RestApiException {
try {
deleteChangeEdit.apply(changeResource, new DeleteChangeEdit.Input());
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot delete change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete change edit", e);
}
}
@@ -115,8 +116,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
public void rebase() throws RestApiException {
try {
rebaseChangeEdit.apply(changeResource, null);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot rebase change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot rebase change edit", e);
}
}
@@ -129,8 +130,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
public void publish(PublishChangeEditInput publishChangeEditInput) throws RestApiException {
try {
publishChangeEdit.apply(changeResource, publishChangeEditInput);
} catch (IOException | OrmException | UpdateException e) {
throw new RestApiException("Cannot publish change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot publish change edit", e);
}
}
@@ -140,8 +141,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
ChangeEditResource changeEditResource = getChangeEditResource(filePath);
Response<BinaryResult> fileResponse = changeEditsGet.apply(changeEditResource);
return fileResponse.isNone() ? Optional.empty() : Optional.of(fileResponse.value());
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot retrieve file of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve file of change edit", e);
}
}
@@ -152,8 +153,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
renameInput.oldPath = oldFilePath;
renameInput.newPath = newFilePath;
changeEditsPost.apply(changeResource, renameInput);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot rename file of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot rename file of change edit", e);
}
}
@@ -163,8 +164,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
ChangeEdits.Post.Input restoreInput = new ChangeEdits.Post.Input();
restoreInput.restorePath = filePath;
changeEditsPost.apply(changeResource, restoreInput);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot restore file of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot restore file of change edit", e);
}
}
@@ -172,8 +173,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
public void modifyFile(String filePath, RawInput newContent) throws RestApiException {
try {
changeEditsPut.apply(changeResource.getControl(), filePath, newContent);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot modify file of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot modify file of change edit", e);
}
}
@@ -181,8 +182,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
public void deleteFile(String filePath) throws RestApiException {
try {
changeEditDeleteContent.apply(changeResource.getControl(), filePath);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot delete file of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete file of change edit", e);
}
}
@@ -192,8 +193,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
try (BinaryResult binaryResult = getChangeEditCommitMessage.apply(changeResource)) {
return binaryResult.asString();
}
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot get commit message of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot get commit message of change edit", e);
}
}
@@ -203,8 +204,8 @@ public class ChangeEditApiImpl implements ChangeEditApi {
input.message = newCommitMessage;
try {
modifyChangeEditCommitMessage.apply(changeResource, input);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot modify commit message of change edit", e);
} catch (Exception e) {
throw asRestApiException("Cannot modify commit message of change edit", e);
}
}

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.api.changes;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@@ -24,7 +25,6 @@ import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.TopLevelResource;
@@ -32,15 +32,10 @@ import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.server.change.ChangesCollection;
import com.google.gerrit.server.change.CreateChange;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.query.change.QueryChanges;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.List;
@Singleton
@@ -78,8 +73,8 @@ class ChangesImpl implements Changes {
public ChangeApi id(String id) throws RestApiException {
try {
return api.create(changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot parse change", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse change", e);
}
}
@@ -88,12 +83,8 @@ class ChangesImpl implements Changes {
try {
ChangeInfo out = createChange.apply(TopLevelResource.INSTANCE, in).value();
return api.create(changes.parse(new Change.Id(out._number)));
} catch (OrmException
| IOException
| InvalidChangeOperationException
| UpdateException
| PermissionBackendException e) {
throw new RestApiException("Cannot create change", e);
} catch (Exception e) {
throw asRestApiException("Cannot create change", e);
}
}
@@ -137,8 +128,8 @@ class ChangesImpl implements Changes {
List<ChangeInfo> infos = (List<ChangeInfo>) result;
return ImmutableList.copyOf(infos);
} catch (AuthException | OrmException e) {
throw new RestApiException("Cannot query changes", e);
} catch (Exception e) {
throw asRestApiException("Cannot query changes", e);
}
}
}

View File

@@ -14,12 +14,13 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.CommentApi;
import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.CommentResource;
import com.google.gerrit.server.change.GetComment;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -41,8 +42,8 @@ class CommentApiImpl implements CommentApi {
public CommentInfo get() throws RestApiException {
try {
return getComment.apply(comment);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve comment", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve comment", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.DraftApi;
import com.google.gerrit.extensions.api.changes.DraftInput;
import com.google.gerrit.extensions.common.CommentInfo;
@@ -22,8 +24,6 @@ import com.google.gerrit.server.change.DeleteDraftComment;
import com.google.gerrit.server.change.DraftCommentResource;
import com.google.gerrit.server.change.GetDraftComment;
import com.google.gerrit.server.change.PutDraftComment;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -53,8 +53,8 @@ class DraftApiImpl implements DraftApi {
public CommentInfo get() throws RestApiException {
try {
return getDraft.apply(draft);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve draft", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve draft", e);
}
}
@@ -62,8 +62,8 @@ class DraftApiImpl implements DraftApi {
public CommentInfo update(DraftInput in) throws RestApiException {
try {
return putDraft.apply(draft, in).value();
} catch (UpdateException | OrmException e) {
throw new RestApiException("Cannot update draft", e);
} catch (Exception e) {
throw asRestApiException("Cannot update draft", e);
}
}
@@ -71,8 +71,8 @@ class DraftApiImpl implements DraftApi {
public void delete() throws RestApiException {
try {
deleteDraft.apply(draft, null);
} catch (UpdateException e) {
throw new RestApiException("Cannot delete draft", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete draft", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.FileApi;
import com.google.gerrit.extensions.common.DiffInfo;
import com.google.gerrit.extensions.restapi.BinaryResult;
@@ -21,11 +23,8 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.FileResource;
import com.google.gerrit.server.change.GetContent;
import com.google.gerrit.server.change.GetDiff;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
class FileApiImpl implements FileApi {
interface Factory {
@@ -47,8 +46,8 @@ class FileApiImpl implements FileApi {
public BinaryResult content() throws RestApiException {
try {
return getContent.apply(file);
} catch (IOException | OrmException e) {
throw new RestApiException("Cannot retrieve file content", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve file content", e);
}
}
@@ -56,8 +55,8 @@ class FileApiImpl implements FileApi {
public DiffInfo diff() throws RestApiException {
try {
return getDiff.apply(file).value();
} catch (IOException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot retrieve diff", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve diff", e);
}
}
@@ -65,8 +64,8 @@ class FileApiImpl implements FileApi {
public DiffInfo diff(String base) throws RestApiException {
try {
return getDiff.setBase(base).apply(file).value();
} catch (IOException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot retrieve diff", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve diff", e);
}
}
@@ -74,8 +73,8 @@ class FileApiImpl implements FileApi {
public DiffInfo diff(int parent) throws RestApiException {
try {
return getDiff.setParent(parent).apply(file).value();
} catch (OrmException | InvalidChangeOperationException | IOException e) {
throw new RestApiException("Cannot retrieve diff", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve diff", e);
}
}
@@ -104,8 +103,8 @@ class FileApiImpl implements FileApi {
}
try {
return getDiff.apply(file).value();
} catch (IOException | InvalidChangeOperationException | OrmException e) {
throw new RestApiException("Cannot retrieve diff", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve diff", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.DeleteReviewerInput;
import com.google.gerrit.extensions.api.changes.DeleteVoteInput;
import com.google.gerrit.extensions.api.changes.ReviewerApi;
@@ -23,8 +25,6 @@ import com.google.gerrit.server.change.DeleteVote;
import com.google.gerrit.server.change.ReviewerResource;
import com.google.gerrit.server.change.VoteResource;
import com.google.gerrit.server.change.Votes;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.util.Map;
@@ -55,8 +55,8 @@ public class ReviewerApiImpl implements ReviewerApi {
public Map<String, Short> votes() throws RestApiException {
try {
return listVotes.apply(reviewer);
} catch (OrmException e) {
throw new RestApiException("Cannot list votes", e);
} catch (Exception e) {
throw asRestApiException("Cannot list votes", e);
}
}
@@ -64,8 +64,8 @@ public class ReviewerApiImpl implements ReviewerApi {
public void deleteVote(String label) throws RestApiException {
try {
deleteVote.apply(new VoteResource(reviewer, label), null);
} catch (UpdateException e) {
throw new RestApiException("Cannot delete vote", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete vote", e);
}
}
@@ -73,8 +73,8 @@ public class ReviewerApiImpl implements ReviewerApi {
public void deleteVote(DeleteVoteInput input) throws RestApiException {
try {
deleteVote.apply(new VoteResource(reviewer, input.label), input);
} catch (UpdateException e) {
throw new RestApiException("Cannot delete vote", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete vote", e);
}
}
@@ -87,8 +87,8 @@ public class ReviewerApiImpl implements ReviewerApi {
public void remove(DeleteReviewerInput input) throws RestApiException {
try {
deleteReviewer.apply(reviewer, input);
} catch (UpdateException e) {
throw new RestApiException("Cannot remove reviewer", e);
} catch (Exception e) {
throw asRestApiException("Cannot remove reviewer", e);
}
}
}

View File

@@ -14,8 +14,9 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.changes.CherryPickInput;
@@ -72,14 +73,9 @@ import com.google.gerrit.server.change.RobotComments;
import com.google.gerrit.server.change.Submit;
import com.google.gerrit.server.change.TestSubmitType;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.patch.PatchListNotAvailableException;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -214,8 +210,8 @@ class RevisionApiImpl implements RevisionApi {
public void review(ReviewInput in) throws RestApiException {
try {
review.apply(revision, in);
} catch (OrmException | UpdateException | IOException | PermissionBackendException e) {
throw new RestApiException("Cannot post review", e);
} catch (Exception e) {
throw asRestApiException("Cannot post review", e);
}
}
@@ -229,8 +225,8 @@ class RevisionApiImpl implements RevisionApi {
public void submit(SubmitInput in) throws RestApiException {
try {
submit.apply(revision, in);
} catch (OrmException | IOException | PermissionBackendException e) {
throw new RestApiException("Cannot submit change", e);
} catch (Exception e) {
throw asRestApiException("Cannot submit change", e);
}
}
@@ -244,8 +240,8 @@ class RevisionApiImpl implements RevisionApi {
try {
submitPreview.setFormat(format);
return submitPreview.apply(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot get submit preview", e);
} catch (Exception e) {
throw asRestApiException("Cannot get submit preview", e);
}
}
@@ -253,8 +249,8 @@ class RevisionApiImpl implements RevisionApi {
public void publish() throws RestApiException {
try {
publish.apply(revision, new PublishDraftPatchSet.Input());
} catch (UpdateException e) {
throw new RestApiException("Cannot publish draft patch set", e);
} catch (Exception e) {
throw asRestApiException("Cannot publish draft patch set", e);
}
}
@@ -262,8 +258,8 @@ class RevisionApiImpl implements RevisionApi {
public void delete() throws RestApiException {
try {
deleteDraft.apply(revision, null);
} catch (UpdateException | OrmException | PermissionBackendException e) {
throw new RestApiException("Cannot delete draft ps", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete draft ps", e);
}
}
@@ -277,12 +273,8 @@ class RevisionApiImpl implements RevisionApi {
public ChangeApi rebase(RebaseInput in) throws RestApiException {
try {
return changes.id(rebase.apply(revision, in)._number);
} catch (OrmException
| EmailException
| UpdateException
| IOException
| PermissionBackendException e) {
throw new RestApiException("Cannot rebase ps", e);
} catch (Exception e) {
throw asRestApiException("Cannot rebase ps", e);
}
}
@@ -291,8 +283,8 @@ class RevisionApiImpl implements RevisionApi {
try (Repository repo = repoManager.openRepository(revision.getProject());
RevWalk rw = new RevWalk(repo)) {
return rebaseUtil.canRebase(revision.getPatchSet(), revision.getChange().getDest(), repo, rw);
} catch (IOException e) {
throw new RestApiException("Cannot check if rebase is possible", e);
} catch (Exception e) {
throw asRestApiException("Cannot check if rebase is possible", e);
}
}
@@ -300,8 +292,8 @@ class RevisionApiImpl implements RevisionApi {
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
try {
return changes.id(cherryPick.apply(revision, in)._number);
} catch (OrmException | IOException | UpdateException e) {
throw new RestApiException("Cannot cherry pick", e);
} catch (Exception e) {
throw asRestApiException("Cannot cherry pick", e);
}
}
@@ -310,8 +302,8 @@ class RevisionApiImpl implements RevisionApi {
try {
return revisionReviewerApi.create(
revisionReviewers.parse(revision, IdString.fromDecoded(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot parse reviewer", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse reviewer", e);
}
}
@@ -326,7 +318,7 @@ class RevisionApiImpl implements RevisionApi {
}
view.apply(files.parse(revision, IdString.fromDecoded(path)), new Reviewed.Input());
} catch (Exception e) {
throw new RestApiException("Cannot update reviewed flag", e);
throw asRestApiException("Cannot update reviewed flag", e);
}
}
@@ -336,8 +328,8 @@ class RevisionApiImpl implements RevisionApi {
try {
return ImmutableSet.copyOf(
(Iterable<String>) listFiles.setReviewed(true).apply(revision).value());
} catch (OrmException | IOException | PatchListNotAvailableException e) {
throw new RestApiException("Cannot list reviewed files", e);
} catch (Exception e) {
throw asRestApiException("Cannot list reviewed files", e);
}
}
@@ -345,8 +337,8 @@ class RevisionApiImpl implements RevisionApi {
public MergeableInfo mergeable() throws RestApiException {
try {
return mergeable.apply(revision);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot check mergeability", e);
} catch (Exception e) {
throw asRestApiException("Cannot check mergeability", e);
}
}
@@ -355,8 +347,8 @@ class RevisionApiImpl implements RevisionApi {
try {
mergeable.setOtherBranches(true);
return mergeable.apply(revision);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot check mergeability", e);
} catch (Exception e) {
throw asRestApiException("Cannot check mergeability", e);
}
}
@@ -365,8 +357,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, FileInfo> files() throws RestApiException {
try {
return (Map<String, FileInfo>) listFiles.apply(revision).value();
} catch (OrmException | IOException | PatchListNotAvailableException e) {
throw new RestApiException("Cannot retrieve files", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve files", e);
}
}
@@ -375,8 +367,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, FileInfo> files(String base) throws RestApiException {
try {
return (Map<String, FileInfo>) listFiles.setBase(base).apply(revision).value();
} catch (OrmException | IOException | PatchListNotAvailableException e) {
throw new RestApiException("Cannot retrieve files", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve files", e);
}
}
@@ -385,8 +377,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, FileInfo> files(int parentNum) throws RestApiException {
try {
return (Map<String, FileInfo>) listFiles.setParent(parentNum).apply(revision).value();
} catch (OrmException | IOException | PatchListNotAvailableException e) {
throw new RestApiException("Cannot retrieve files", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve files", e);
}
}
@@ -399,8 +391,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, List<CommentInfo>> comments() throws RestApiException {
try {
return listComments.apply(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve comments", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve comments", e);
}
}
@@ -408,8 +400,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, List<RobotCommentInfo>> robotComments() throws RestApiException {
try {
return listRobotComments.apply(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve robot comments", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve robot comments", e);
}
}
@@ -417,8 +409,8 @@ class RevisionApiImpl implements RevisionApi {
public List<CommentInfo> commentsAsList() throws RestApiException {
try {
return listComments.getComments(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve comments", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve comments", e);
}
}
@@ -426,8 +418,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, List<CommentInfo>> drafts() throws RestApiException {
try {
return listDrafts.apply(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve drafts", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve drafts", e);
}
}
@@ -435,8 +427,8 @@ class RevisionApiImpl implements RevisionApi {
public List<RobotCommentInfo> robotCommentsAsList() throws RestApiException {
try {
return listRobotComments.getComments(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve robot comments", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve robot comments", e);
}
}
@@ -444,8 +436,8 @@ class RevisionApiImpl implements RevisionApi {
public EditInfo applyFix(String fixId) throws RestApiException {
try {
return applyFix.apply(fixes.parse(revision, IdString.fromDecoded(fixId)), null).value();
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot apply fix", e);
} catch (Exception e) {
throw asRestApiException("Cannot apply fix", e);
}
}
@@ -453,8 +445,8 @@ class RevisionApiImpl implements RevisionApi {
public List<CommentInfo> draftsAsList() throws RestApiException {
try {
return listDrafts.getComments(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve drafts", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve drafts", e);
}
}
@@ -462,8 +454,8 @@ class RevisionApiImpl implements RevisionApi {
public DraftApi draft(String id) throws RestApiException {
try {
return draftFactory.create(drafts.parse(revision, IdString.fromDecoded(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve draft", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve draft", e);
}
}
@@ -476,8 +468,8 @@ class RevisionApiImpl implements RevisionApi {
.id(revision.getChange().getId().get())
.revision(revision.getPatchSet().getId().get())
.draft(id);
} catch (UpdateException | OrmException e) {
throw new RestApiException("Cannot create draft", e);
} catch (Exception e) {
throw asRestApiException("Cannot create draft", e);
}
}
@@ -485,8 +477,8 @@ class RevisionApiImpl implements RevisionApi {
public CommentApi comment(String id) throws RestApiException {
try {
return commentFactory.create(comments.parse(revision, IdString.fromDecoded(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve comment", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve comment", e);
}
}
@@ -494,8 +486,8 @@ class RevisionApiImpl implements RevisionApi {
public RobotCommentApi robotComment(String id) throws RestApiException {
try {
return robotCommentFactory.create(robotComments.parse(revision, IdString.fromDecoded(id)));
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve robot comment", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve robot comment", e);
}
}
@@ -503,8 +495,8 @@ class RevisionApiImpl implements RevisionApi {
public BinaryResult patch() throws RestApiException {
try {
return getPatch.apply(revision);
} catch (IOException e) {
throw new RestApiException("Cannot get patch", e);
} catch (Exception e) {
throw asRestApiException("Cannot get patch", e);
}
}
@@ -512,8 +504,8 @@ class RevisionApiImpl implements RevisionApi {
public BinaryResult patch(String path) throws RestApiException {
try {
return getPatch.setPath(path).apply(revision);
} catch (IOException e) {
throw new RestApiException("Cannot get patch", e);
} catch (Exception e) {
throw asRestApiException("Cannot get patch", e);
}
}
@@ -521,8 +513,8 @@ class RevisionApiImpl implements RevisionApi {
public Map<String, ActionInfo> actions() throws RestApiException {
try {
return revisionActions.apply(revision).value();
} catch (OrmException e) {
throw new RestApiException("Cannot get actions", e);
} catch (Exception e) {
throw asRestApiException("Cannot get actions", e);
}
}
@@ -530,8 +522,8 @@ class RevisionApiImpl implements RevisionApi {
public SubmitType submitType() throws RestApiException {
try {
return getSubmitType.apply(revision);
} catch (OrmException e) {
throw new RestApiException("Cannot get submit type", e);
} catch (Exception e) {
throw asRestApiException("Cannot get submit type", e);
}
}
@@ -539,8 +531,8 @@ class RevisionApiImpl implements RevisionApi {
public SubmitType testSubmitType(TestSubmitRuleInput in) throws RestApiException {
try {
return testSubmitType.apply(revision, in);
} catch (OrmException e) {
throw new RestApiException("Cannot test submit type", e);
} catch (Exception e) {
throw asRestApiException("Cannot test submit type", e);
}
}
@@ -554,8 +546,8 @@ class RevisionApiImpl implements RevisionApi {
gml.setUninterestingParent(getUninterestingParent());
gml.setAddLinks(getAddLinks());
return gml.apply(revision).value();
} catch (IOException e) {
throw new RestApiException("Cannot get merge list", e);
} catch (Exception e) {
throw asRestApiException("Cannot get merge list", e);
}
}
};
@@ -567,8 +559,8 @@ class RevisionApiImpl implements RevisionApi {
in.description = description;
try {
putDescription.apply(revision, in);
} catch (UpdateException | PermissionBackendException e) {
throw new RestApiException("Cannot set description", e);
} catch (Exception e) {
throw asRestApiException("Cannot set description", e);
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.DeleteVoteInput;
import com.google.gerrit.extensions.api.changes.RevisionReviewerApi;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -21,8 +23,6 @@ import com.google.gerrit.server.change.DeleteVote;
import com.google.gerrit.server.change.ReviewerResource;
import com.google.gerrit.server.change.VoteResource;
import com.google.gerrit.server.change.Votes;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.util.Map;
@@ -48,8 +48,8 @@ public class RevisionReviewerApiImpl implements RevisionReviewerApi {
public Map<String, Short> votes() throws RestApiException {
try {
return listVotes.apply(reviewer);
} catch (OrmException e) {
throw new RestApiException("Cannot list votes", e);
} catch (Exception e) {
throw asRestApiException("Cannot list votes", e);
}
}
@@ -57,8 +57,8 @@ public class RevisionReviewerApiImpl implements RevisionReviewerApi {
public void deleteVote(String label) throws RestApiException {
try {
deleteVote.apply(new VoteResource(reviewer, label), null);
} catch (UpdateException e) {
throw new RestApiException("Cannot delete vote", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete vote", e);
}
}
@@ -66,8 +66,8 @@ public class RevisionReviewerApiImpl implements RevisionReviewerApi {
public void deleteVote(DeleteVoteInput input) throws RestApiException {
try {
deleteVote.apply(new VoteResource(reviewer, input.label), input);
} catch (UpdateException e) {
throw new RestApiException("Cannot delete vote", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete vote", e);
}
}
}

View File

@@ -14,12 +14,13 @@
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.RobotCommentApi;
import com.google.gerrit.extensions.common.RobotCommentInfo;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.GetRobotComment;
import com.google.gerrit.server.change.RobotCommentResource;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
@@ -41,8 +42,8 @@ public class RobotCommentApiImpl implements RobotCommentApi {
public RobotCommentInfo get() throws RestApiException {
try {
return getComment.apply(comment);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve robot comment", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve robot comment", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.config;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.common.Version;
import com.google.gerrit.extensions.api.config.AccessCheckInfo;
import com.google.gerrit.extensions.api.config.AccessCheckInput;
@@ -32,13 +34,9 @@ import com.google.gerrit.server.config.GetPreferences;
import com.google.gerrit.server.config.GetServerInfo;
import com.google.gerrit.server.config.SetDiffPreferences;
import com.google.gerrit.server.config.SetPreferences;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton
public class ServerImpl implements Server {
@@ -77,8 +75,8 @@ public class ServerImpl implements Server {
public ServerInfo getInfo() throws RestApiException {
try {
return getServerInfo.apply(new ConfigResource());
} catch (IOException e) {
throw new RestApiException("Cannot get server info", e);
} catch (Exception e) {
throw asRestApiException("Cannot get server info", e);
}
}
@@ -86,8 +84,8 @@ public class ServerImpl implements Server {
public GeneralPreferencesInfo getDefaultPreferences() throws RestApiException {
try {
return getPreferences.apply(new ConfigResource());
} catch (IOException | ConfigInvalidException e) {
throw new RestApiException("Cannot get default general preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot get default general preferences", e);
}
}
@@ -96,8 +94,8 @@ public class ServerImpl implements Server {
throws RestApiException {
try {
return setPreferences.apply(new ConfigResource(), in);
} catch (IOException | ConfigInvalidException e) {
throw new RestApiException("Cannot set default general preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot set default general preferences", e);
}
}
@@ -105,8 +103,8 @@ public class ServerImpl implements Server {
public DiffPreferencesInfo getDefaultDiffPreferences() throws RestApiException {
try {
return getDiffPreferences.apply(new ConfigResource());
} catch (IOException | ConfigInvalidException e) {
throw new RestApiException("Cannot get default diff preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot get default diff preferences", e);
}
}
@@ -115,8 +113,8 @@ public class ServerImpl implements Server {
throws RestApiException {
try {
return setDiffPreferences.apply(new ConfigResource(), in);
} catch (IOException | ConfigInvalidException e) {
throw new RestApiException("Cannot set default diff preferences", e);
} catch (Exception e) {
throw asRestApiException("Cannot set default diff preferences", e);
}
}
@@ -124,8 +122,8 @@ public class ServerImpl implements Server {
public ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException {
try {
return checkConsistency.get().apply(new ConfigResource(), in);
} catch (IOException e) {
throw new RestApiException("Cannot check consistency", e);
} catch (Exception e) {
throw asRestApiException("Cannot check consistency", e);
}
}
@@ -133,8 +131,8 @@ public class ServerImpl implements Server {
public AccessCheckInfo checkAccess(AccessCheckInput in) throws RestApiException {
try {
return checkAccess.get().apply(new ConfigResource(), in);
} catch (OrmException | IOException | PermissionBackendException e) {
throw new RestApiException("Cannot check access", e);
} catch (Exception e) {
throw asRestApiException("Cannot check access", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.groups;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.api.groups.GroupApi;
import com.google.gerrit.extensions.common.AccountInfo;
@@ -41,10 +43,8 @@ import com.google.gerrit.server.group.PutDescription;
import com.google.gerrit.server.group.PutName;
import com.google.gerrit.server.group.PutOptions;
import com.google.gerrit.server.group.PutOwner;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@@ -119,8 +119,8 @@ class GroupApiImpl implements GroupApi {
public GroupInfo get() throws RestApiException {
try {
return getGroup.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve group", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve group", e);
}
}
@@ -128,8 +128,8 @@ class GroupApiImpl implements GroupApi {
public GroupInfo detail() throws RestApiException {
try {
return getDetail.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot retrieve group", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve group", e);
}
}
@@ -146,8 +146,8 @@ class GroupApiImpl implements GroupApi {
putName.apply(rsrc, in);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(name, e);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot put group name", e);
} catch (Exception e) {
throw asRestApiException("Cannot put group name", e);
}
}
@@ -155,8 +155,8 @@ class GroupApiImpl implements GroupApi {
public GroupInfo owner() throws RestApiException {
try {
return getOwner.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot get group owner", e);
} catch (Exception e) {
throw asRestApiException("Cannot get group owner", e);
}
}
@@ -166,8 +166,8 @@ class GroupApiImpl implements GroupApi {
in.owner = owner;
try {
putOwner.apply(rsrc, in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot put group owner", e);
} catch (Exception e) {
throw asRestApiException("Cannot put group owner", e);
}
}
@@ -182,8 +182,8 @@ class GroupApiImpl implements GroupApi {
in.description = description;
try {
putDescription.apply(rsrc, in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot put group description", e);
} catch (Exception e) {
throw asRestApiException("Cannot put group description", e);
}
}
@@ -196,8 +196,8 @@ class GroupApiImpl implements GroupApi {
public void options(GroupOptionsInfo options) throws RestApiException {
try {
putOptions.apply(rsrc, options);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot put group options", e);
} catch (Exception e) {
throw asRestApiException("Cannot put group options", e);
}
}
@@ -211,8 +211,8 @@ class GroupApiImpl implements GroupApi {
listMembers.setRecursive(recursive);
try {
return listMembers.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot list group members", e);
} catch (Exception e) {
throw asRestApiException("Cannot list group members", e);
}
}
@@ -220,8 +220,8 @@ class GroupApiImpl implements GroupApi {
public void addMembers(String... members) throws RestApiException {
try {
addMembers.apply(rsrc, AddMembers.Input.fromMembers(Arrays.asList(members)));
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot add group members", e);
} catch (Exception e) {
throw asRestApiException("Cannot add group members", e);
}
}
@@ -229,8 +229,8 @@ class GroupApiImpl implements GroupApi {
public void removeMembers(String... members) throws RestApiException {
try {
deleteMembers.apply(rsrc, AddMembers.Input.fromMembers(Arrays.asList(members)));
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot remove group members", e);
} catch (Exception e) {
throw asRestApiException("Cannot remove group members", e);
}
}
@@ -238,8 +238,8 @@ class GroupApiImpl implements GroupApi {
public List<GroupInfo> includedGroups() throws RestApiException {
try {
return listGroups.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot list included groups", e);
} catch (Exception e) {
throw asRestApiException("Cannot list included groups", e);
}
}
@@ -247,8 +247,8 @@ class GroupApiImpl implements GroupApi {
public void addGroups(String... groups) throws RestApiException {
try {
addGroups.apply(rsrc, AddIncludedGroups.Input.fromGroups(Arrays.asList(groups)));
} catch (OrmException e) {
throw new RestApiException("Cannot add group members", e);
} catch (Exception e) {
throw asRestApiException("Cannot add group members", e);
}
}
@@ -256,8 +256,8 @@ class GroupApiImpl implements GroupApi {
public void removeGroups(String... groups) throws RestApiException {
try {
deleteGroups.apply(rsrc, AddIncludedGroups.Input.fromGroups(Arrays.asList(groups)));
} catch (OrmException e) {
throw new RestApiException("Cannot remove group members", e);
} catch (Exception e) {
throw asRestApiException("Cannot remove group members", e);
}
}
@@ -265,8 +265,8 @@ class GroupApiImpl implements GroupApi {
public List<? extends GroupAuditEventInfo> auditLog() throws RestApiException {
try {
return getAuditLog.apply(rsrc);
} catch (OrmException e) {
throw new RestApiException("Cannot get audit log", e);
} catch (Exception e) {
throw asRestApiException("Cannot get audit log", e);
}
}
@@ -274,8 +274,8 @@ class GroupApiImpl implements GroupApi {
public void index() throws RestApiException {
try {
index.apply(rsrc, new Index.Input());
} catch (IOException e) {
throw new RestApiException("Cannot index group", e);
} catch (Exception e) {
throw asRestApiException("Cannot index group", e);
}
}
}

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.server.api.groups;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.groups.GroupApi;
import com.google.gerrit.extensions.api.groups.GroupInput;
@@ -33,13 +34,10 @@ import com.google.gerrit.server.group.ListGroups;
import com.google.gerrit.server.group.QueryGroups;
import com.google.gerrit.server.permissions.GlobalPermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ProjectsCollection;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.List;
import java.util.SortedMap;
@@ -99,8 +97,8 @@ class GroupsImpl implements Groups {
permissionBackend.user(user).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
GroupInfo info = impl.apply(TopLevelResource.INSTANCE, in);
return id(info.id);
} catch (OrmException | IOException | PermissionBackendException e) {
throw new RestApiException("Cannot create group " + in.name, e);
} catch (Exception e) {
throw asRestApiException("Cannot create group " + in.name, e);
}
}
@@ -122,8 +120,8 @@ class GroupsImpl implements Groups {
for (String project : req.getProjects()) {
try {
list.addProject(projects.parse(tlr, IdString.fromDecoded(project)).getControl());
} catch (IOException | PermissionBackendException e) {
throw new RestApiException("Error looking up project " + project, e);
} catch (Exception e) {
throw asRestApiException("Error looking up project " + project, e);
}
}
@@ -136,8 +134,8 @@ class GroupsImpl implements Groups {
if (req.getUser() != null) {
try {
list.setUser(accounts.parse(req.getUser()).getAccountId());
} catch (OrmException e) {
throw new RestApiException("Error looking up user " + req.getUser(), e);
} catch (Exception e) {
throw asRestApiException("Error looking up user " + req.getUser(), e);
}
}
@@ -148,8 +146,8 @@ class GroupsImpl implements Groups {
list.setSuggest(req.getSuggest());
try {
return list.apply(tlr);
} catch (OrmException e) {
throw new RestApiException("Cannot list groups", e);
} catch (Exception e) {
throw asRestApiException("Cannot list groups", e);
}
}
@@ -178,8 +176,8 @@ class GroupsImpl implements Groups {
myQueryGroups.addOption(option);
}
return myQueryGroups.apply(TopLevelResource.INSTANCE);
} catch (OrmException e) {
throw new RestApiException("Cannot query groups", e);
} catch (Exception e) {
throw asRestApiException("Cannot query groups", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.projects;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.projects.BranchApi;
import com.google.gerrit.extensions.api.projects.BranchInfo;
import com.google.gerrit.extensions.api.projects.BranchInput;
@@ -28,7 +30,6 @@ import com.google.gerrit.server.project.FileResource;
import com.google.gerrit.server.project.FilesCollection;
import com.google.gerrit.server.project.GetContent;
import com.google.gerrit.server.project.ProjectResource;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
@@ -69,8 +70,8 @@ public class BranchApiImpl implements BranchApi {
try {
createBranchFactory.create(ref).apply(project, input);
return this;
} catch (IOException e) {
throw new RestApiException("Cannot create branch", e);
} catch (Exception e) {
throw asRestApiException("Cannot create branch", e);
}
}
@@ -78,8 +79,8 @@ public class BranchApiImpl implements BranchApi {
public BranchInfo get() throws RestApiException {
try {
return resource().getBranchInfo();
} catch (IOException e) {
throw new RestApiException("Cannot read branch", e);
} catch (Exception e) {
throw asRestApiException("Cannot read branch", e);
}
}
@@ -87,8 +88,8 @@ public class BranchApiImpl implements BranchApi {
public void delete() throws RestApiException {
try {
deleteBranch.apply(resource(), new DeleteBranch.Input());
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot delete branch", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete branch", e);
}
}
@@ -97,8 +98,8 @@ public class BranchApiImpl implements BranchApi {
try {
FileResource resource = filesCollection.parse(resource(), IdString.fromDecoded(path));
return getContent.apply(resource);
} catch (IOException e) {
throw new RestApiException("Cannot retrieve file", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve file", e);
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.projects;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.Changes;
import com.google.gerrit.extensions.api.changes.CherryPickInput;
@@ -21,11 +23,8 @@ import com.google.gerrit.extensions.api.projects.CommitApi;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.CherryPickCommit;
import com.google.gerrit.server.project.CommitResource;
import com.google.gerrit.server.update.UpdateException;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
public class CommitApiImpl implements CommitApi {
public interface Factory {
@@ -48,8 +47,8 @@ public class CommitApiImpl implements CommitApi {
public ChangeApi cherryPick(CherryPickInput input) throws RestApiException {
try {
return changes.id(cherryPickCommit.apply(commitResource, input)._number);
} catch (OrmException | IOException | UpdateException e) {
throw new RestApiException("Cannot cherry pick", e);
} catch (Exception e) {
throw asRestApiException("Cannot cherry pick", e);
}
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.projects;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.access.ProjectAccessInfo;
import com.google.gerrit.extensions.api.access.ProjectAccessInput;
import com.google.gerrit.extensions.api.projects.BranchApi;
@@ -39,7 +41,6 @@ import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.permissions.GlobalPermission;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.ChildProjectsCollection;
import com.google.gerrit.server.project.CommitsCollection;
import com.google.gerrit.server.project.CreateProject;
@@ -57,12 +58,9 @@ import com.google.gerrit.server.project.ProjectsCollection;
import com.google.gerrit.server.project.PutConfig;
import com.google.gerrit.server.project.PutDescription;
import com.google.gerrit.server.project.SetAccess;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import java.io.IOException;
import java.util.List;
import org.eclipse.jgit.errors.ConfigInvalidException;
public class ProjectApiImpl implements ProjectApi {
interface Factory {
@@ -269,8 +267,8 @@ public class ProjectApiImpl implements ProjectApi {
permissionBackend.user(user).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
impl.apply(TopLevelResource.INSTANCE, in);
return projectApi.create(projects.parse(name));
} catch (IOException | ConfigInvalidException | PermissionBackendException e) {
throw new RestApiException("Cannot create project: " + e.getMessage(), e);
} catch (Exception e) {
throw asRestApiException("Cannot create project: " + e.getMessage(), e);
}
}
@@ -291,8 +289,8 @@ public class ProjectApiImpl implements ProjectApi {
public ProjectAccessInfo access() throws RestApiException {
try {
return getAccess.apply(checkExists());
} catch (IOException e) {
throw new RestApiException("Cannot get access rights", e);
} catch (Exception e) {
throw asRestApiException("Cannot get access rights", e);
}
}
@@ -300,8 +298,8 @@ public class ProjectApiImpl implements ProjectApi {
public ProjectAccessInfo access(ProjectAccessInput p) throws RestApiException {
try {
return setAccess.apply(checkExists(), p);
} catch (IOException | PermissionBackendException e) {
throw new RestApiException("Cannot put access rights", e);
} catch (Exception e) {
throw asRestApiException("Cannot put access rights", e);
}
}
@@ -309,8 +307,8 @@ public class ProjectApiImpl implements ProjectApi {
public void description(DescriptionInput in) throws RestApiException {
try {
putDescription.apply(checkExists(), in);
} catch (IOException e) {
throw new RestApiException("Cannot put project description", e);
} catch (Exception e) {
throw asRestApiException("Cannot put project description", e);
}
}
@@ -342,8 +340,8 @@ public class ProjectApiImpl implements ProjectApi {
listBranches.setMatchRegex(request.getRegex());
try {
return listBranches.apply(checkExists());
} catch (IOException e) {
throw new RestApiException("Cannot list branches", e);
} catch (Exception e) {
throw asRestApiException("Cannot list branches", e);
}
}
@@ -364,8 +362,8 @@ public class ProjectApiImpl implements ProjectApi {
listTags.setMatchRegex(request.getRegex());
try {
return listTags.apply(checkExists());
} catch (IOException e) {
throw new RestApiException("Cannot list tags", e);
} catch (Exception e) {
throw asRestApiException("Cannot list tags", e);
}
}
@@ -380,8 +378,8 @@ public class ProjectApiImpl implements ProjectApi {
list.setRecursive(recursive);
try {
return list.apply(checkExists());
} catch (PermissionBackendException e) {
throw new RestApiException("Cannot list children", e);
} catch (Exception e) {
throw asRestApiException("Cannot list children", e);
}
}
@@ -389,8 +387,8 @@ public class ProjectApiImpl implements ProjectApi {
public ChildProjectApi child(String name) throws RestApiException {
try {
return childApi.create(children.parse(checkExists(), IdString.fromDecoded(name)));
} catch (IOException | PermissionBackendException e) {
throw new RestApiException("Cannot parse child project", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse child project", e);
}
}
@@ -408,8 +406,8 @@ public class ProjectApiImpl implements ProjectApi {
public void deleteBranches(DeleteBranchesInput in) throws RestApiException {
try {
deleteBranches.apply(checkExists(), in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot delete branches", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete branches", e);
}
}
@@ -417,8 +415,8 @@ public class ProjectApiImpl implements ProjectApi {
public void deleteTags(DeleteTagsInput in) throws RestApiException {
try {
deleteTags.apply(checkExists(), in);
} catch (OrmException | IOException e) {
throw new RestApiException("Cannot delete tags", e);
} catch (Exception e) {
throw asRestApiException("Cannot delete tags", e);
}
}
@@ -426,8 +424,8 @@ public class ProjectApiImpl implements ProjectApi {
public CommitApi commit(String commit) throws RestApiException {
try {
return commitApi.create(commitsCollection.parse(checkExists(), IdString.fromDecoded(commit)));
} catch (IOException e) {
throw new RestApiException("Cannot parse commit", e);
} catch (Exception e) {
throw asRestApiException("Cannot parse commit", e);
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.projects;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.projects.ProjectApi;
import com.google.gerrit.extensions.api.projects.ProjectInput;
import com.google.gerrit.extensions.api.projects.Projects;
@@ -28,7 +30,6 @@ import com.google.gerrit.server.project.ProjectsCollection;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.SortedMap;
@Singleton
@@ -53,8 +54,8 @@ class ProjectsImpl implements Projects {
return api.create(projects.parse(name));
} catch (UnprocessableEntityException e) {
return api.create(name);
} catch (IOException | PermissionBackendException e) {
throw new RestApiException("Cannot retrieve project", e);
} catch (Exception e) {
throw asRestApiException("Cannot retrieve project", e);
}
}
@@ -80,8 +81,8 @@ class ProjectsImpl implements Projects {
public SortedMap<String, ProjectInfo> getAsMap() throws RestApiException {
try {
return list(this);
} catch (PermissionBackendException e) {
throw new RestApiException("project list unavailable", e);
} catch (Exception e) {
throw asRestApiException("project list unavailable", e);
}
}
};

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.server.api.projects;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.projects.TagApi;
import com.google.gerrit.extensions.api.projects.TagInfo;
import com.google.gerrit.extensions.api.projects.TagInput;
@@ -25,7 +27,6 @@ import com.google.gerrit.server.project.ListTags;
import com.google.gerrit.server.project.ProjectResource;
import com.google.gerrit.server.project.TagResource;
import com.google.gerrit.server.project.TagsCollection;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.io.IOException;
@@ -63,8 +64,8 @@ public class TagApiImpl implements TagApi {
try {
createTagFactory.create(ref).apply(project, input);
return this;
} catch (IOException e) {
throw new RestApiException("Cannot create tag", e);
} catch (Exception e) {
throw asRestApiException("Cannot create tag", e);
}
}
@@ -72,8 +73,8 @@ public class TagApiImpl implements TagApi {
public TagInfo get() throws RestApiException {
try {
return listTags.get(project, IdString.fromDecoded(ref));
} catch (IOException e) {
throw new RestApiException(e.getMessage());
} catch (Exception e) {
throw asRestApiException("Cannot get tag", e);
}
}
@@ -81,8 +82,8 @@ public class TagApiImpl implements TagApi {
public void delete() throws RestApiException {
try {
deleteTag.apply(resource(), new DeleteTag.Input());
} catch (OrmException | IOException e) {
throw new RestApiException(e.getMessage());
} catch (Exception e) {
throw asRestApiException("Cannot delete tag", e);
}
}