Search in sources :

Example 1 with TypeMarker

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());
}
Also used : Response(okhttp3.Response) ServiceException(com.palantir.conjure.java.api.errors.ServiceException) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) TypeMarker(com.palantir.conjure.java.undertow.lib.TypeMarker) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.jupiter.api.Test)

Example 2 with TypeMarker

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());
}
Also used : Response(okhttp3.Response) ServiceException(com.palantir.conjure.java.api.errors.ServiceException) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) TypeMarker(com.palantir.conjure.java.undertow.lib.TypeMarker) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.jupiter.api.Test)

Example 3 with TypeMarker

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());
}
Also used : Response(okhttp3.Response) ServiceException(com.palantir.conjure.java.api.errors.ServiceException) SerializableError(com.palantir.conjure.java.api.errors.SerializableError) TypeMarker(com.palantir.conjure.java.undertow.lib.TypeMarker) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RemoteException(com.palantir.conjure.java.api.errors.RemoteException) Test(org.junit.jupiter.api.Test)

Aggregations

RemoteException (com.palantir.conjure.java.api.errors.RemoteException)3 SerializableError (com.palantir.conjure.java.api.errors.SerializableError)3 ServiceException (com.palantir.conjure.java.api.errors.ServiceException)3 TypeMarker (com.palantir.conjure.java.undertow.lib.TypeMarker)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Response (okhttp3.Response)3 Test (org.junit.jupiter.api.Test)3