use of com.palantir.conjure.java.undertow.lib.TypeMarker in project conjure-java by palantir.
the class ConjureExceptionHandlerTest method handles401RemoteException.
@Test
public void handles401RemoteException() throws IOException {
SerializableError remoteError = SerializableError.forException(new ServiceException(ErrorType.create(Code.UNAUTHORIZED, "Test:ErrorName"), SafeArg.of("foo", "bar")));
exception = new RemoteException(remoteError, ErrorType.UNAUTHORIZED.httpErrorCode());
Response response = execute();
// Propagates errorInstanceId and does not change error code and name
// Does not propagate args
SerializableError expectedPropagatedError = SerializableError.builder().errorCode(ErrorType.UNAUTHORIZED.code().toString()).errorName("Test:ErrorName").errorInstanceId(remoteError.errorInstanceId()).build();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Encodings.json().serializer(new TypeMarker<SerializableError>() {
}).serialize(expectedPropagatedError, stream);
assertThat(response.body().string()).isEqualTo(stream.toString(StandardCharsets.UTF_8));
assertThat(response.code()).isEqualTo(ErrorType.UNAUTHORIZED.httpErrorCode());
}
use of com.palantir.conjure.java.undertow.lib.TypeMarker in project conjure-java by palantir.
the class ConjureExceptionHandlerTest method handles403RemoteException.
@Test
public void handles403RemoteException() throws IOException {
SerializableError remoteError = SerializableError.forException(new ServiceException(ErrorType.create(Code.PERMISSION_DENIED, "Test:ErrorName"), SafeArg.of("foo", "bar")));
exception = new RemoteException(remoteError, ErrorType.PERMISSION_DENIED.httpErrorCode());
Response response = execute();
// Propagates errorInstanceId and does not change error code and name
// Does not propagate args
SerializableError expectedPropagatedError = SerializableError.builder().errorCode(ErrorType.PERMISSION_DENIED.code().toString()).errorName("Test:ErrorName").errorInstanceId(remoteError.errorInstanceId()).build();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Encodings.json().serializer(new TypeMarker<SerializableError>() {
}).serialize(expectedPropagatedError, stream);
assertThat(response.body().string()).isEqualTo(stream.toString(StandardCharsets.UTF_8));
assertThat(response.code()).isEqualTo(ErrorType.PERMISSION_DENIED.httpErrorCode());
}
use of com.palantir.conjure.java.undertow.lib.TypeMarker in project conjure-java by palantir.
the class ConjureExceptionHandlerTest method handlesRemoteException.
@Test
public void handlesRemoteException() throws IOException {
SerializableError remoteError = SerializableError.forException(new ServiceException(ErrorType.CONFLICT, SafeArg.of("foo", "bar")));
exception = new RemoteException(remoteError, ErrorType.CONFLICT.httpErrorCode());
Response response = execute();
// Propagates errorInstanceId and changes error code and name to INTERNAL
// Does not propagate args
SerializableError expectedPropagatedError = SerializableError.builder().errorCode(ErrorType.INTERNAL.code().toString()).errorName(ErrorType.INTERNAL.name()).errorInstanceId(remoteError.errorInstanceId()).build();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Encodings.json().serializer(new TypeMarker<SerializableError>() {
}).serialize(expectedPropagatedError, stream);
assertThat(response.body().string()).isEqualTo(stream.toString(StandardCharsets.UTF_8));
// remote exceptions should result in 500 status
assertThat(response.code()).isEqualTo(ErrorType.INTERNAL.httpErrorCode());
}
Aggregations