'Rethrow Exception from slack api Response payload, or handle it appropriately

The Slack conversations.join api returns a Slack API Exception (part of Response Body - i.e ConversationsJoinResponse object returned from Slack Library response) when it is unable to join a slack channel for some reason , it is sent as a part of API Response object which is a ConversationsJoinResponse object .

I have used this Api which returns the Slack Library Response object.

Documentation - https://api.slack.com/methods/conversations.join

Api - https://slack.com/api/conversations.join

IMHO it would be better to throw the exception I received from the Api itself.

So I am trying to rethrow the same exception I get from the slack library and returns the error message in Response object returned by the library i.e ConversationsJoinResponse object.

Would this be the right way to handle the exception where the SlackApiException class takes a Request Body and a message.

logger.error("Error Joining Channel - $channelId : ${response.error}")
throw SlackApiException(
  Response.Builder().code(400).request(
    Request.Builder().url("https://slack.com/api/conversations.join").build())
    .message(response.error).build(),
  response.error
)

Any help with figuring the appropriate way to handle the Api Response is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source