Search in sources :

Example 1 with ChatError

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

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

the class CreateChatThreadResultConverter method convert.

/**
 * Maps from {@link com.azure.android.communication.chat.implementation.models.CreateChatThreadResult} to
 * {@link CreateChatThreadResult}.
 */
public static CreateChatThreadResult convert(com.azure.android.communication.chat.implementation.models.CreateChatThreadResult obj, ClientLogger logger) {
    if (obj == null) {
        return null;
    }
    CreateChatThreadResult createChatThreadResult = new CreateChatThreadResult().setChatThreadProperties(ChatThreadPropertiesConverter.convert(obj.getChatThread(), logger));
    if (obj.getInvalidParticipants() != null) {
        List<ChatError> invalidParticipants = new ArrayList<>(obj.getInvalidParticipants().size());
        for (CommunicationError invalidParticipant : obj.getInvalidParticipants()) {
            invalidParticipants.add(ChatErrorConverter.convert(invalidParticipant));
        }
        createChatThreadResult.setInvalidParticipants(invalidParticipants);
    }
    return createChatThreadResult;
}
Also used : CreateChatThreadResult(com.azure.android.communication.chat.models.CreateChatThreadResult) ChatError(com.azure.android.communication.chat.models.ChatError) CommunicationError(com.azure.android.communication.chat.implementation.models.CommunicationError) ArrayList(java.util.ArrayList)

Aggregations

ChatError (com.azure.android.communication.chat.models.ChatError)2 CommunicationError (com.azure.android.communication.chat.implementation.models.CommunicationError)1 CommunicationErrorResponseException (com.azure.android.communication.chat.implementation.models.CommunicationErrorResponseException)1 ChatErrorResponseException (com.azure.android.communication.chat.models.ChatErrorResponseException)1 CreateChatThreadResult (com.azure.android.communication.chat.models.CreateChatThreadResult)1 ArrayList (java.util.ArrayList)1