从 slack api 响应有效负载中重新抛出异常,或适当处理它
当 Slack conversations.join api 由于某种原因无法加入 slack 频道时,它会返回 Slack API 异常(响应正文的一部分 - 即从 Slack 库响应返回的 ConversationsJoinResponse 对象),它作为 API 响应对象的一部分发送是一个 ConversationsJoinResponse 对象。
我使用了这个 Api,它返回 Slack 库响应对象。
文档 - https://api.slack.com/methods/conversations.join
Api - https://slack.com/api/conversations.join
恕我直言,它会最好抛出我从 Api 本身收到的异常。
因此,我尝试重新抛出从 slack 库获得的相同异常,并在库返回的 Response 对象(即 ConversationsJoinResponse 对象)中返回错误消息。
这是处理 SlackApiException 类采用请求正文和消息的异常的正确方法吗?
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
)
如果您能帮助找出处理 Api 响应的适当方法,我们将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论