Search in sources :

Example 1 with CommunicationErrorResponseException

use of com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException in project azure-sdk-for-android by Azure.

the class CommunicationErrorResponseExceptionConverter method convert.

/**
 * Maps from {@link CommunicationErrorResponseException} to {@link ChatErrorResponseException}.
 * Keeps other kind of exceptions as it is.
 */
public static RuntimeException convert(Throwable throwable) {
    if (throwable == null) {
        return null;
    }
    if (throwable instanceof CommunicationErrorResponseException) {
        // translate CommunicationErrorResponseException to ChatErrorResponseException
        ChatError error = null;
        CommunicationErrorResponseException exception = (CommunicationErrorResponseException) throwable;
        if (exception.getValue() != null) {
            error = ChatErrorConverter.convert(exception.getValue().getError());
        }
        return new ChatErrorResponseException(exception.getMessage(), exception.getResponse(), error);
    } else if (throwable instanceof RuntimeException) {
        // avoid double-wrapping for already unchecked exception
        return (RuntimeException) throwable;
    } else {
        // wrap checked exception in a unchecked runtime exception
        return new RuntimeException(throwable);
    }
}
Also used : ChatError(com.azure.android.communication.chat.models.ChatError) ChatErrorResponseException(com.azure.android.communication.chat.models.ChatErrorResponseException) CommunicationErrorResponseException(com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException)

Example 2 with CommunicationErrorResponseException

use of com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException in project azure-sdk-for-android by Azure.

the class ChatAsyncImplClientTest method getNotFoundOnNonExistingChatThreadWithResponse.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void getNotFoundOnNonExistingChatThreadWithResponse(HttpClient httpClient) {
    setupTest(httpClient);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        CompletableFuture<Response<ChatThreadProperties>> completableFuture = client.getChatThreadClient().getChatThreadPropertiesWithResponseAsync("19:00000000000000000000000000000000@thread.v2", null);
        completableFuture.get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof CommunicationErrorResponseException);
    HttpResponseException exception = (HttpResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(404, exception.getResponse().getStatusCode());
}
Also used : Response(com.azure.android.core.rest.Response) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) HttpResponseException(com.azure.android.core.http.exception.HttpResponseException) ExecutionException(java.util.concurrent.ExecutionException) CommunicationErrorResponseException(com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with CommunicationErrorResponseException

use of com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException in project azure-sdk-for-android by Azure.

the class ChatAsyncImplClientTest method getNotFoundOnNonExistingChatThread.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void getNotFoundOnNonExistingChatThread(HttpClient httpClient) {
    setupTest(httpClient);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        CompletableFuture<ChatThreadProperties> completableFuture = client.getChatThreadClient().getChatThreadPropertiesAsync("19:00000000000000000000000000000000@thread.v2");
        completableFuture.get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof CommunicationErrorResponseException);
    HttpResponseException exception = (HttpResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(404, exception.getResponse().getStatusCode());
}
Also used : ChatThreadProperties(com.azure.android.communication.chat.implementation.models.ChatThreadProperties) HttpResponseException(com.azure.android.core.http.exception.HttpResponseException) ExecutionException(java.util.concurrent.ExecutionException) CommunicationErrorResponseException(com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

CommunicationErrorResponseException (com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException)3 HttpResponseException (com.azure.android.core.http.exception.HttpResponseException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ChatThreadProperties (com.azure.android.communication.chat.implementation.models.ChatThreadProperties)1 ChatError (com.azure.android.communication.chat.models.ChatError)1 ChatErrorResponseException (com.azure.android.communication.chat.models.ChatErrorResponseException)1 Response (com.azure.android.core.rest.Response)1 PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)1