Skip to content

Commit 717d1cf

Browse files
committed
refactor(channel_messages): Added stautus check + raise exception with details
1 parent 9e51b8b commit 717d1cf

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: office365
2-
version: 1.25.5
2+
version: 1.25.6
33

44
crystal: ">= 0.36.1"
55

src/channel_messages.cr

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,45 @@ module Office365::ChannelMessages
3333
end
3434

3535
def list_channel_messages(response : HTTP::Client::Response)
36-
ChatMessageList.from_json(response.body)
36+
if response.success?
37+
ChatMessageList.from_json(response.body)
38+
else
39+
raise "error listing channel messages #{response.status} (#{response.status_code}\n#{response.body}"
40+
end
3741
end
3842

3943
def get_channel_message(team_id : String, channel_id : String, message_id : String)
4044
request = graph_http_request(request_method: "GET", path: "/v1.0/teams/#{team_id}/channels/#{channel_id}/messages/#{message_id}")
4145
response = graph_request(request)
42-
ChatMessage.from_json(response.body)
46+
if response.success?
47+
ChatMessage.from_json(response.body)
48+
else
49+
raise "error getting channel message #{response.status} (#{response.status_code}\n#{response.body}"
50+
end
4351
end
4452

4553
def send_channel_message(team_id : String, channel_id : String, message : String | IO)
4654
body = message.is_a?(IO) ? message.gets_to_end : message
4755
chat = ChatMessage.new(body: body)
4856
request = graph_http_request(request_method: "POST", path: "/v1.0/teams/#{team_id}/channels/#{channel_id}/messages", data: chat.to_json)
49-
graph_request(request)
57+
response = graph_request(request)
58+
59+
if response.success?
60+
ChatMessage.from_json(response.body)
61+
else
62+
raise "error sending channel message #{response.status} (#{response.status_code}\n#{response.body}"
63+
end
5064
end
5165

5266
def send_channel_message(team_id : String, channel_id : String, message : String | IO, content_type : String)
5367
body = message.is_a?(IO) ? message.gets_to_end : message
5468
chat = ChatMessage.new(content: body, content_type: content_type)
5569
request = graph_http_request(request_method: "POST", path: "/v1.0/teams/#{team_id}/channels/#{channel_id}/messages", data: chat.to_json)
56-
graph_request(request)
70+
response = graph_request(request)
71+
if response.success?
72+
ChatMessage.from_json(response.body)
73+
else
74+
raise "error sending channel message #{response.status} (#{response.status_code}\n#{response.body}"
75+
end
5776
end
5877
end

0 commit comments

Comments
 (0)