Skip to content

Commit

Permalink
RemoteException emits more safeargs (#655)
Browse files Browse the repository at this point in the history
RemoteExceptions now emit SafeArgs for `errorInstanceId`, `errorCode` and `errorName` (previously it was just `errorInstanceId`)
  • Loading branch information
iamdanfox authored Apr 28, 2021
1 parent 4f573cd commit ee7be0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-655.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: RemoteExceptions now emit SafeArgs for `errorInstanceId`, `errorCode` and `errorName` (previously it was just `errorInstanceId`)
links:
- https://github.com/palantir/conjure-java-runtime-api/pull/655
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
import com.palantir.logsafe.Arg;
import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.SafeLoggable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/** An exception thrown by an RPC client to indicate remote/server-side failure. */
public final class RemoteException extends RuntimeException implements SafeLoggable {
private static final long serialVersionUID = 1L;
private static final String ERROR_INSTANCE_ID = "errorInstanceId";
private static final String ERROR_CODE = "errorCode";
private static final String ERROR_NAME = "errorName";

private final String message;
private final String stableMessage;
Expand All @@ -49,7 +53,10 @@ public RemoteException(SerializableError error, int status) {
this.message = this.stableMessage + " with instance ID " + error.errorInstanceId();
this.error = error;
this.status = status;
this.args = Collections.singletonList(SafeArg.of("errorInstanceId", error.errorInstanceId()));
this.args = Collections.unmodifiableList(Arrays.asList(
SafeArg.of(ERROR_INSTANCE_ID, error.errorInstanceId()),
SafeArg.of(ERROR_NAME, error.errorName()),
SafeArg.of(ERROR_CODE, error.errorCode())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void testArgsIsEmpty() {
.putParameters("param", "value")
.build(),
500);
assertThat(remoteException.getArgs()).containsExactly(SafeArg.of("errorInstanceId", "errorId"));
assertThat(remoteException.getArgs())
.containsExactlyInAnyOrder(
SafeArg.of("errorInstanceId", "errorId"),
SafeArg.of("errorCode", "errorCode"),
SafeArg.of("errorName", "errorName"));
}
}

0 comments on commit ee7be0b

Please sign in to comment.