Make RestApiException(String, Exception) constructor protected

This constructor should only be used by subclasses and for wrapping
other exceptions, but not for signaling internal server errors.

Throwing RestApiExceptions to signal internal server errors is bad
since all RestApiExceptions are exempt from retries and auto-tracing.

To prevent that a RestApiException is accidentally thrown to signal an
internal server error we:

* make the RestApiException(String, Exception) constructor protected so
  that it can only be used by subclasses
* offer a static method for exception wrapping

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I3495cb63f66a669ac5849d5f28c3ce8cc4e5ae95
This commit is contained in:
Edwin Kempin
2019-12-23 15:00:42 +01:00
parent b5bee5779e
commit 7c97209f6d
4 changed files with 8 additions and 4 deletions

View File

@@ -32,7 +32,7 @@ public class ApiUtil {
public static RestApiException asRestApiException(String msg, Exception e)
throws RuntimeException {
Throwables.throwIfUnchecked(e);
return e instanceof RestApiException ? (RestApiException) e : new RestApiException(msg, e);
return e instanceof RestApiException ? (RestApiException) e : RestApiException.wrap(msg, e);
}
private ApiUtil() {}