Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication Services - Chat preview5 error shape #19999

Merged
merged 3 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -85,7 +87,7 @@ public Mono<CreateChatThreadResult> 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.
*/
Expand All @@ -104,7 +106,7 @@ public Mono<Response<CreateChatThreadResult>> 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.
*/
Expand All @@ -124,7 +126,7 @@ Mono<Response<CreateChatThreadResult>> 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.
*/
Expand All @@ -148,7 +150,7 @@ public PagedFlux<ChatThreadItem> 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.
*/
Expand Down Expand Up @@ -191,7 +193,7 @@ PagedFlux<ChatThreadItem> 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.
*/
Expand All @@ -212,7 +214,7 @@ public Mono<Void> 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.
*/
Expand All @@ -231,7 +233,7 @@ public Mono<Response<Void>> 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.
*/
Expand All @@ -245,8 +247,12 @@ Mono<Response<Void>> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -83,7 +83,7 @@ public Response<CreateChatThreadResult> 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)
Expand All @@ -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.
*/
Expand All @@ -109,7 +109,7 @@ public Response<Void> 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.
*/
Expand All @@ -124,7 +124,7 @@ public PagedIterable<ChatThreadItem> 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.
*/
Expand Down
Loading