From 2396d078c8b1338bf981398b2ea9419c54aa7be5 Mon Sep 17 00:00:00 2001 From: Daniel Gerlag Date: Sat, 20 Mar 2021 16:48:57 -0700 Subject: [PATCH] Communication Services - Chat preview5 error shape (#19999) * translate CommunicationErrorResponseException to HttpResponseException * add exceptions to javadoc --- .../communication/chat/ChatAsyncClient.java | 28 +++++--- .../azure/communication/chat/ChatClient.java | 14 ++-- .../chat/ChatThreadAsyncClient.java | 67 ++++++++++--------- .../communication/chat/ChatThreadClient.java | 58 ++++++++-------- .../models/ChatErrorResponseException.java | 39 +++++++++++ 5 files changed, 128 insertions(+), 78 deletions(-) create mode 100644 sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatErrorResponseException.java diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java index 648214031677f..644aa031e9d77 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java @@ -2,9 +2,11 @@ // Licensed under the MIT License. package com.azure.communication.chat; +import com.azure.communication.chat.implementation.converters.ChatErrorConverter; import com.azure.communication.chat.implementation.converters.CreateChatThreadResultConverter; import com.azure.communication.chat.implementation.models.CommunicationErrorResponseException; -import com.azure.core.exception.HttpResponseException; +import com.azure.communication.chat.models.ChatError; +import com.azure.communication.chat.models.ChatErrorResponseException; import reactor.core.publisher.Mono; import com.azure.communication.chat.models.ChatThreadItem; @@ -59,7 +61,7 @@ public ChatThreadAsyncClient getChatThreadClient(String chatThreadId) { * Creates a chat thread. * * @param options Options for creating a chat thread. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. */ @@ -85,7 +87,7 @@ public Mono createChatThread(CreateChatThreadOptions opt * Creates a chat thread. * * @param options Options for creating a chat thread. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. */ @@ -104,7 +106,7 @@ public Mono> createChatThreadWithResponse(Creat * * @param options Options for creating a chat thread. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. */ @@ -124,7 +126,7 @@ Mono> createChatThread(CreateChatThreadOptions /** * Gets the list of chat threads of a user. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the paged list of chat threads of a user. */ @@ -148,7 +150,7 @@ public PagedFlux listChatThreads() { * Gets the list of chat threads of a user. * * @param listThreadsOptions The request options. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the paged list of chat threads of a user. */ @@ -191,7 +193,7 @@ PagedFlux listChatThreads(ListChatThreadsOptions listThreadsOpti * Deletes a chat thread. * * @param chatThreadId Chat thread id to delete. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -212,7 +214,7 @@ public Mono deleteChatThread(String chatThreadId) { * Deletes a chat thread. * * @param chatThreadId Chat thread id to delete. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -231,7 +233,7 @@ public Mono> deleteChatThreadWithResponse(String chatThreadId) { * * @param chatThreadId Chat thread id to delete. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -245,8 +247,12 @@ Mono> deleteChatThread(String chatThreadId, Context context) { } } - private RuntimeException translateException(CommunicationErrorResponseException exception) { - return new HttpResponseException(exception.getMessage(), exception.getResponse(), exception.getValue()); + private ChatErrorResponseException translateException(CommunicationErrorResponseException exception) { + ChatError error = null; + if (exception.getValue() != null) { + error = ChatErrorConverter.convert(exception.getValue().getError()); + } + return new ChatErrorResponseException(exception.getMessage(), exception.getResponse(), error); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatClient.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatClient.java index ea8ff2dc8bbf6..dba26d78a35d0 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatClient.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatClient.java @@ -2,6 +2,7 @@ // Licensed under the MIT License. package com.azure.communication.chat; +import com.azure.communication.chat.models.ChatErrorResponseException; import com.azure.communication.chat.models.ChatThreadItem; import com.azure.communication.chat.models.CreateChatThreadOptions; import com.azure.communication.chat.models.CreateChatThreadResult; @@ -10,7 +11,6 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.exception.HttpResponseException; import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.SimpleResponse; @@ -53,7 +53,7 @@ public ChatThreadClient getChatThreadClient(String chatThreadId) { * Creates a chat thread. * * @param options Options for creating a chat thread. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. */ @@ -67,7 +67,7 @@ public CreateChatThreadResult createChatThread(CreateChatThreadOptions options) * * @param options Options for creating a chat thread. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. */ @@ -83,7 +83,7 @@ public Response createChatThreadWithResponse(CreateChatT * Deletes a chat thread. * * @param chatThreadId Chat thread id to delete. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -96,7 +96,7 @@ public void deleteChatThread(String chatThreadId) { * * @param chatThreadId Chat thread id to delete. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -109,7 +109,7 @@ public Response deleteChatThreadWithResponse(String chatThreadId, Context /** * Gets the list of chat threads of a user. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the paged list of chat threads of a user. */ @@ -124,7 +124,7 @@ public PagedIterable listChatThreads() { * * @param listThreadsOptions The request options. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the paged list of chat threads of a user. */ diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadAsyncClient.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadAsyncClient.java index e22a34e87a37d..a65f51271a9b8 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadAsyncClient.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadAsyncClient.java @@ -5,12 +5,13 @@ import com.azure.communication.chat.implementation.ChatThreadsImpl; import com.azure.communication.chat.implementation.converters.AddChatParticipantsResultConverter; +import com.azure.communication.chat.implementation.converters.ChatErrorConverter; import com.azure.communication.chat.implementation.converters.ChatThreadPropertiesConverter; import com.azure.communication.chat.implementation.models.CommunicationErrorResponseException; import com.azure.communication.chat.models.ChatError; +import com.azure.communication.chat.models.ChatErrorResponseException; import com.azure.communication.chat.models.ChatThreadProperties; import com.azure.communication.chat.models.InvalidParticipantException; -import com.azure.core.exception.HttpResponseException; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -85,7 +86,7 @@ public String getChatThreadId() { * Updates a thread's topic. * * @param topic The new topic. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -106,7 +107,7 @@ public Mono updateTopic(String topic) { * Updates a thread's properties. * * @param topic The new topic. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -125,7 +126,7 @@ public Mono> updateTopicWithResponse(String topic) { * * @param topic The new topic. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -147,7 +148,7 @@ Mono> updateTopic(String topic, Context context) { * Adds participants to a thread. If participants already exist, no change occurs. * * @param participants Collection of participants to add. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the result. */ @@ -168,7 +169,7 @@ public Mono addParticipants(Iterable participants) { * Adds participants to a thread. If participants already exist, no change occurs. * * @param participants Collection of participants to add. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the result. */ @@ -186,7 +187,7 @@ public Mono> addParticipantsWithResponse(Ite * Adds a participant to a thread. If the participant already exists, no change occurs. * * @param participant The new participant. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws InvalidParticipantException thrown if the participant is rejected by the server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return nothing. @@ -203,7 +204,7 @@ public Mono addParticipant(ChatParticipant participant) { * Adds a participant to a thread. If the participant already exists, no change occurs. * * @param participant The new participant. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws InvalidParticipantException thrown if the participant is rejected by the server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. @@ -222,7 +223,7 @@ public Mono> addParticipantWithResponse(ChatParticipant participa * * @param participant The new participant. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws InvalidParticipantException thrown if the participant is rejected by the server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. @@ -274,7 +275,7 @@ Mono> addParticipants(Iterable removeParticipant(CommunicationIdentifier identifier) { * Remove a participant from a thread. * * @param identifier Identity of the participant to remove from the thread. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -333,7 +334,7 @@ Mono> removeParticipant(CommunicationIdentifier identifier, Conte /** * Gets the participants of a thread. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the participants of a thread. */ @@ -377,7 +378,7 @@ PagedFlux listParticipants(ListParticipantsOptions listParticip * Sends a message to a thread. * * @param options Options for sending the message. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the SendChatMessageResult. */ @@ -396,7 +397,7 @@ public Mono sendMessage(SendChatMessageOptions options) { * Sends a message to a thread. * * @param options Options for sending the message. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the SendChatMessageResult. */ @@ -433,7 +434,7 @@ Mono> sendMessage(SendChatMessageOptions options * Gets a message by id. * * @param chatMessageId The message id. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a message by id. */ @@ -459,7 +460,7 @@ public Mono getMessage(String chatMessageId) { * Gets a message by id. * * @param chatMessageId The message id. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a message by id. */ @@ -496,7 +497,7 @@ Mono> getMessage(String chatMessageId, Context context) { /** * Gets a list of messages from a thread. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a paged list of messages from a thread. */ @@ -521,7 +522,7 @@ public PagedFlux listMessages() { * Gets a list of messages from a thread. * * @param listMessagesOptions The request options. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a paged list of messages from a thread. */ @@ -581,7 +582,7 @@ PagedFlux listMessages(ListChatMessagesOptions listMessagesOptions, * * @param chatMessageId The message id. * @param options Options for updating the message. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -604,7 +605,7 @@ public Mono updateMessage(String chatMessageId, UpdateChatMessageOptions o * * @param chatMessageId The message id. * @param options Options for updating the message. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -641,7 +642,7 @@ Mono> updateMessage(String chatMessageId, UpdateChatMessageOption * Deletes a message. * * @param chatMessageId The message id. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -662,7 +663,7 @@ public Mono deleteMessage(String chatMessageId) { * Deletes a message. * * @param chatMessageId The message id. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -696,7 +697,7 @@ Mono> deleteMessage(String chatMessageId, Context context) { /** * Posts a typing event to a thread, on behalf of a user. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -715,7 +716,7 @@ public Mono sendTypingNotification() { /** * Posts a typing event to a thread, on behalf of a user. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -748,7 +749,7 @@ Mono> sendTypingNotification(Context context) { * Posts a read receipt event to a thread, on behalf of a user. * * @param chatMessageId The id of the chat message that was read. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -769,7 +770,7 @@ public Mono sendReadReceipt(String chatMessageId) { * Posts a read receipt event to a thread, on behalf of a user. * * @param chatMessageId The id of the chat message that was read. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -805,7 +806,7 @@ Mono> sendReadReceipt(String chatMessageId, Context context) { /** * Gets read receipts for a thread. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return read receipts for a thread. */ @@ -851,7 +852,7 @@ PagedFlux listReadReceipts(ListReadReceiptOptions listRe /** * Gets chat thread properties. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return chat thread properties. */ @@ -876,7 +877,7 @@ public Mono getProperties() { /** * Gets chat thread properties. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return chat thread properties. */ @@ -936,7 +937,11 @@ private PagedFlux pagedFluxConvert(PagedFlux originalPagedFlux, return PagedFlux.create(provider); } - private RuntimeException translateException(CommunicationErrorResponseException exception) { - return new HttpResponseException(exception.getMessage(), exception.getResponse(), exception.getValue()); + private ChatErrorResponseException translateException(CommunicationErrorResponseException exception) { + ChatError error = null; + if (exception.getValue() != null) { + error = ChatErrorConverter.convert(exception.getValue().getError()); + } + return new ChatErrorResponseException(exception.getMessage(), exception.getResponse(), error); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadClient.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadClient.java index a4dc6fd52c36d..d5f231c0f03fc 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadClient.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatThreadClient.java @@ -3,6 +3,7 @@ package com.azure.communication.chat; import com.azure.communication.chat.models.AddChatParticipantsResult; +import com.azure.communication.chat.models.ChatErrorResponseException; import com.azure.communication.chat.models.ChatMessage; import com.azure.communication.chat.models.ChatParticipant; import com.azure.communication.chat.models.ChatMessageReadReceipt; @@ -18,7 +19,6 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.exception.HttpResponseException; import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; @@ -59,7 +59,7 @@ public String getChatThreadId() { * Updates a thread's topic. * * @param topic The new topic. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -73,7 +73,7 @@ public void updateTopic(String topic) { * * @param topic The new topic. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -87,7 +87,7 @@ public Response updateTopicWithResponse(String topic, Context context) { * Adds participants to a thread. If participants already exist, no change occurs. * * @param participants Collection of participants to add. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -101,7 +101,7 @@ public void addParticipants(Iterable participants) { * * @param participants Collection of participants to add. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -115,7 +115,7 @@ public Response addParticipantsWithResponse( * Adds a participant to a thread. If the participant already exists, no change occurs. * * @param participant The new participant. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws InvalidParticipantException thrown if the participant is rejected by the server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @@ -129,7 +129,7 @@ public void addParticipant(ChatParticipant participant) { * * @param participant The new participant. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws InvalidParticipantException thrown if the participant is rejected by the server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the response. @@ -144,7 +144,7 @@ public Response addParticipantWithResponse(ChatParticipant participant, Co * * @param identifier Identity of the participant to remove from the thread. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -158,7 +158,7 @@ public Response removeParticipantWithResponse(CommunicationIdentifier iden * Remove a participant from a thread. * * @param identifier Identity of the thread participant to remove from the thread. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -170,7 +170,7 @@ public void removeParticipant(CommunicationIdentifier identifier) { /** * Gets the participants of a thread. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the participants of a thread. */ @@ -185,7 +185,7 @@ public PagedIterable listParticipants() { * * @param listParticipantsOptions The request options. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the participants of a thread. */ @@ -200,7 +200,7 @@ public PagedIterable listParticipants(ListParticipantsOptions l * * @param options Options for sending the message. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the SendChatMessageResult. */ @@ -214,7 +214,7 @@ public Response sendMessageWithResponse(SendChatMessageOp * Sends a message to a thread. * * @param options Options for sending the message. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the SendChatMessageResult. */ @@ -229,7 +229,7 @@ public SendChatMessageResult sendMessage(SendChatMessageOptions options) { * * @param chatMessageId The message id. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a message by id. */ @@ -243,7 +243,7 @@ public Response getMessageWithResponse(String chatMessageId, Contex * Gets a message by id. * * @param chatMessageId The message id. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a message by id. */ @@ -256,7 +256,7 @@ public ChatMessage getMessage(String chatMessageId) { /** * Gets a list of messages from a thread. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a list of messages from a thread. */ @@ -271,7 +271,7 @@ public PagedIterable listMessages() { * * @param listMessagesOptions The request options. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return a list of messages from a thread. */ @@ -287,7 +287,7 @@ public PagedIterable listMessages(ListChatMessagesOptions listMessa * @param chatMessageId The message id. * @param options Options for updating the message. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -303,7 +303,7 @@ public Response updateMessageWithResponse( * * @param chatMessageId The message id. * @param options Options for updating the message. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -317,7 +317,7 @@ public void updateMessage(String chatMessageId, UpdateChatMessageOptions options * * @param chatMessageId The message id. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -331,7 +331,7 @@ public Response deleteMessageWithResponse(String chatMessageId, Context co * Deletes a message. * * @param chatMessageId The message id. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -344,7 +344,7 @@ public void deleteMessage(String chatMessageId) { * Posts a typing event to a thread, on behalf of a user. * * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -357,7 +357,7 @@ public Response sendTypingNotificationWithResponse(Context context) { /** * Posts a typing event to a thread, on behalf of a user. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -370,7 +370,7 @@ public void sendTypingNotification() { * * @param chatMessageId The id of the chat message that was read. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return the completion. */ @@ -384,7 +384,7 @@ public Response sendReadReceiptWithResponse(String chatMessageId, Context * Posts a read receipt event to a thread, on behalf of a user. * * @param chatMessageId The id of the chat message that was read. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. */ @ServiceMethod(returns = ReturnType.SINGLE) @@ -396,7 +396,7 @@ public void sendReadReceipt(String chatMessageId) { /** * Gets read receipts for a thread. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return read receipts for a thread. */ @@ -411,7 +411,7 @@ public PagedIterable listReadReceipts() { * * @param listReadReceiptOptions The additional options for this operation. * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return read receipts for a thread. */ @@ -424,7 +424,7 @@ public PagedIterable listReadReceipts(ListReadReceiptOpt /** * Gets chat thread properties. * - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return chat thread properties. */ @@ -437,7 +437,7 @@ public ChatThreadProperties getProperties() { * Gets chat thread properties. * * @param context The context to associate with this operation. - * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ChatErrorResponseException thrown if the request is rejected by server. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. * @return chat thread properties. */ diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatErrorResponseException.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatErrorResponseException.java new file mode 100644 index 0000000000000..bd3f027a3bd4e --- /dev/null +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatErrorResponseException.java @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.communication.chat.models; + +import com.azure.core.exception.HttpResponseException; +import com.azure.core.http.HttpResponse; + +/** + * Exception thrown on chat specific errors + */ +public class ChatErrorResponseException extends HttpResponseException { + /** + * Initializes a new instance of the ChatErrorResponseException class. + * + * @param message the exception message or the response content if a message is not available. + * @param response the HTTP response. + */ + public ChatErrorResponseException(String message, HttpResponse response) { + super(message, response); + } + + /** + * Initializes a new instance of the ChatErrorResponseException class. + * + * @param message the exception message or the response content if a message is not available. + * @param response the HTTP response. + * @param value the deserialized response value. + */ + public ChatErrorResponseException( + String message, HttpResponse response, ChatError value) { + super(message, response, value); + } + + @Override + public ChatError getValue() { + return (ChatError) super.getValue(); + } +}