Search in sources :

Example 11 with ChatErrorResponseException

use of com.azure.android.communication.chat.models.ChatErrorResponseException 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 12 with ChatErrorResponseException

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

the class ChatThreadAsyncClientTest method cannotAddParticipantsWithResponseWithInvalidUser.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void cannotAddParticipantsWithResponseWithInvalidUser(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    Iterable<ChatParticipant> participants = addParticipants("8:acs:invalidUserId", this.secondThreadParticipant.getId());
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        this.chatThreadClient.addParticipantsWithResponse(participants, null).get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof ChatErrorResponseException);
    ChatErrorResponseException exception = (ChatErrorResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(400, exception.getResponse().getStatusCode());
}
Also used : ChatErrorResponseException(com.azure.android.communication.chat.models.ChatErrorResponseException) ChatParticipant(com.azure.android.communication.chat.models.ChatParticipant) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with ChatErrorResponseException

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

the class ChatThreadAsyncClientTest method cannotGetMessageWithInvalidId.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void cannotGetMessageWithInvalidId(HttpClient httpClient) throws ExecutionException, InterruptedException {
    setupTest(httpClient);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        this.chatThreadClient.getMessage("invalid_chat_message_id").get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof ChatErrorResponseException);
    ChatErrorResponseException exception = (ChatErrorResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(400, exception.getResponse().getStatusCode());
}
Also used : ChatErrorResponseException(com.azure.android.communication.chat.models.ChatErrorResponseException) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with ChatErrorResponseException

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

the class ChatThreadAsyncClientTest method cannotAddSingleParticipantWithInvalidUser.

@ParameterizedTest
@MethodSource("com.azure.android.core.test.TestBase#getHttpClients")
public void cannotAddSingleParticipantWithInvalidUser(HttpClient httpClient) throws InterruptedException, ExecutionException {
    setupTest(httpClient);
    ExecutionException executionException = assertThrows(ExecutionException.class, () -> {
        this.chatThreadClient.addParticipant(generateParticipant("8:acs:invalidUserId", "name")).get();
    });
    Throwable cause = executionException.getCause();
    assertNotNull(cause);
    assertTrue(cause instanceof ChatErrorResponseException);
    ChatErrorResponseException exception = (ChatErrorResponseException) cause;
    assertNotNull(exception.getResponse());
    assertEquals(400, exception.getResponse().getStatusCode());
}
Also used : ChatErrorResponseException(com.azure.android.communication.chat.models.ChatErrorResponseException) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with ChatErrorResponseException

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

the class ChatThreadAsyncClientTest method getNotFoundOnNonExistingChatThread.

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

Aggregations

ChatErrorResponseException (com.azure.android.communication.chat.models.ChatErrorResponseException)19 ExecutionException (java.util.concurrent.ExecutionException)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 ChatParticipant (com.azure.android.communication.chat.models.ChatParticipant)2 CreateChatThreadOptions (com.azure.android.communication.chat.models.CreateChatThreadOptions)2 UpdateChatMessageOptions (com.azure.android.communication.chat.models.UpdateChatMessageOptions)2 CommunicationUserIdentifier (com.azure.android.communication.common.CommunicationUserIdentifier)2 CommunicationErrorResponseException (com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException)1 ChatError (com.azure.android.communication.chat.models.ChatError)1 ChatThreadProperties (com.azure.android.communication.chat.models.ChatThreadProperties)1 Response (com.azure.android.core.rest.Response)1