Fix exception handling when reading value from REST response

To fail with ISE a REST endpoint can either throw an exception or return
Response.InternalServerError (since change Ie58b4ace6). If
Response.InternalServerError is returned as response and the client
tries to read its value this fails with an UnsupportedOperationException
and the original cause for the ISE is lost. Fix this by throwing the
original cause from Response.InternalServerError#value(). Doing this
requires to handle exceptions when the Response#value() method is
called, but this seems to be manageable. The alternative would be to
revert change Ie58b4ace6.

The current situation is especially bad for analysing test failures that
are caused by ISEs because in this case the test fails with the
UnsupportedOperationException that is thrown by
Response.InternalServerError#value(), but we need to know the original
cause.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I89c0c68bf25a550b9b9be577f42f73c7752f3036
This commit is contained in:
Edwin Kempin
2019-09-18 11:26:14 +02:00
parent 17f7dfe7e3
commit ed411a8dfe
38 changed files with 152 additions and 130 deletions

View File

@@ -12,6 +12,7 @@ java_library(
"//java/com/google/gerrit/git",
"//java/com/google/gerrit/reviewdb:server",
"//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/api",
"//lib:guava",
"//lib/bouncycastle:bcpg-neverlink",
"//lib/bouncycastle:bcprov-neverlink",

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.gpg.api;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
import com.google.gerrit.extensions.api.accounts.GpgKeysInput;
import com.google.gerrit.extensions.common.GpgKeyInfo;
@@ -68,6 +70,8 @@ public class GpgApiAdapterImpl implements GpgApiAdapter {
return gpgKeys.get().list().apply(account).value();
} catch (PGPException | IOException e) {
throw new GpgException(e);
} catch (Exception e) {
throw asRestApiException("Cannot list GPG keys", e);
}
}
@@ -82,6 +86,8 @@ public class GpgApiAdapterImpl implements GpgApiAdapter {
return postGpgKeys.get().apply(account, in).value();
} catch (PGPException | IOException | ConfigInvalidException e) {
throw new GpgException(e);
} catch (Exception e) {
throw asRestApiException("Cannot put GPG keys", e);
}
}

View File

@@ -14,6 +14,8 @@
package com.google.gerrit.gpg.api;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
import com.google.gerrit.extensions.common.GpgKeyInfo;
import com.google.gerrit.extensions.common.Input;
@@ -47,8 +49,8 @@ public class GpgKeyApiImpl implements GpgKeyApi {
public GpgKeyInfo get() throws RestApiException {
try {
return get.apply(rsrc).value();
} catch (IOException e) {
throw new RestApiException("Cannot get GPG key", e);
} catch (Exception e) {
throw asRestApiException("Cannot get GPG key", e);
}
}
@@ -57,7 +59,7 @@ public class GpgKeyApiImpl implements GpgKeyApi {
try {
delete.apply(rsrc, new Input());
} catch (PGPException | IOException | ConfigInvalidException e) {
throw new RestApiException("Cannot delete GPG key", e);
throw asRestApiException("Cannot delete GPG key", e);
}
}
}