Skip to content

Commit

Permalink
Send a message on Slack when the AOC API retrieval fails (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
pil0u authored Nov 22, 2024
1 parent 7a0185c commit 81be7f4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion app/domains/completions/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,23 @@ def fetch_completions(id)
response = https.request(request)
Rails.logger.info "\t#{response.code} #{response.message}"

JSON.parse(response.body)["members"]
begin
JSON.parse(response.body)["members"]
rescue JSON::ParserError => e
client = Slack::Web::Client.new
channel = "#aoc-dev"

if Rails.env.development? || (Rails.env.production? && ENV.fetch("THIS_IS_STAGING", nil))
text = "(not prod) Failed to parse JSON from AoC API"
client.chat_postMessage(channel:, text:)
return
end

text = "⚠️ <@URZ0F4TEF> Failed to parse JSON from AoC API"
message = client.chat_postMessage(channel:, text:)
client.chat_postMessage(channel:, thread_ts: message["message"]["ts"], text: "```#{e.message}```")
raise
end
end

def update_users_sync_status(participant_ids)
Expand Down

0 comments on commit 81be7f4

Please sign in to comment.