use of com.palantir.conjure.java.api.errors.RemoteException 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.api.errors.RemoteException in project conjure-java by palantir.
the class SingleParamServicesTest method runTestCase.
@Test
public void runTestCase() throws Exception {
Assume.assumeFalse(Cases.shouldIgnore(endpointName, jsonString));
System.out.println(String.format("Invoking %s %s(%s)", serviceName, endpointName, jsonString));
Object service = servicesMaps.get(serviceName).asList().get(serviceIndex);
for (Method method : servicesMaps.get(serviceName).getClass().getMethods()) {
String name = method.getName();
if (method.getParameterCount() == 1) {
// conjure-java generates `default` methods for optional query params, we don't want to call these
continue;
}
if (endpointName.get().equals(name)) {
try {
// HACKHACK, index parameter order is different for different services.
if ("singleHeaderService".equals(serviceName)) {
Type type = method.getGenericParameterTypes()[0];
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(service, objectMapper.readValue(jsonString, cls), index);
} else {
Type type = method.getGenericParameterTypes()[1];
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(service, index, objectMapper.readValue(jsonString, cls));
}
log.info("Successfully post param to endpoint {} and index {}", endpointName, index);
} catch (RemoteException e) {
log.error("Caught exception with params: {}", e.getError().parameters(), e);
throw e;
}
}
}
}
use of com.palantir.conjure.java.api.errors.RemoteException in project conjure-java by palantir.
the class EteErrors method testIsError.
@Test
void testIsError() {
RemoteException remoteException = serializeServiceException(ConjureErrors.invalidServiceDefinition("my-service", "service-def"));
assertThat(ConjureErrors.isInvalidServiceDefinition(remoteException)).isTrue();
assertThat(ConjureErrors.isInvalidTypeDefinition(remoteException)).isFalse();
}
use of com.palantir.conjure.java.api.errors.RemoteException in project conjure-java by palantir.
the class EteErrors method testIsError_differentNamespaces.
@Test
void testIsError_differentNamespaces() {
RemoteException remoteException = serializeServiceException(ConjureJavaErrors.javaCompilationFailed());
assertThat(ConjureJavaErrors.isJavaCompilationFailed(remoteException)).isTrue();
assertThat(ConjureJavaOtherErrors.isJavaCompilationFailed(remoteException)).isFalse();
}
use of com.palantir.conjure.java.api.errors.RemoteException in project conjure-java-runtime-api by palantir.
the class RemoteExceptionAssertTest method testSanity.
@Test
public void testSanity() throws Exception {
ErrorType actualType = ErrorType.FAILED_PRECONDITION;
SerializableError error = SerializableError.forException(new ServiceException(actualType));
Assertions.assertThat(new RemoteException(error, actualType.httpErrorCode())).isGeneratedFromErrorType(actualType);
assertThatThrownBy(() -> Assertions.assertThat(new RemoteException(error, actualType.httpErrorCode() + 1)).isGeneratedFromErrorType(actualType)).isInstanceOf(AssertionError.class).hasMessage("Expected error status to be %s, but found %s", actualType.httpErrorCode(), actualType.httpErrorCode() + 1);
}
Aggregations