Skip to content

Commit

Permalink
Reduce complexity by removing sentry tagging
Browse files Browse the repository at this point in the history
- We original talked about tagging the exception so it could be sent to
  a dedicated channel specifically for these rate limit challenge
requests, but as we report all errors, I wanted to keep them all going
to the #monitoring channel. We can monitor that channel with the new
error message and solve the captcha.
  • Loading branch information
mattwr18 committed Sep 13, 2023
1 parent 4608d2f commit 6f0dda1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/adapters/signal_adapter/bad_request_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module SignalAdapter
class BadRequestError < StandardError
def initialize(error_code:, message:)
super("Message was not delivered with error code #{error_code} and message #{message}")
super("Message was not delivered with error code `#{error_code}` and message `#{message}`")
end
end
end
28 changes: 20 additions & 8 deletions app/adapters/signal_adapter/outbound/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ def perform(message:)
response = Net::HTTP.start(url.host, url.port) do |http|
http.request(request)
end
response.value # may raise exception
rescue Net::HTTPClientException => e
ErrorNotifier.report(e, context: {
code: e.response.code,
message: e.response.message,
headers: e.response.to_hash,
body: e.response.body
})
handle_response(response)
end

def data
Expand All @@ -39,6 +32,25 @@ def data
base64_attachments: base64_files
}
end

def handle_response(response)
case response.code.to_i
when 200
# TODO: Do something on success. For example, mark the message as delivered?
# Or should we use deliver receipts as the source of truth.
Rails.logger.debug 'Great!'
when 400..599
error_message = JSON.parse(response.body)['error']
exception = SignalAdapter::BadRequestError.new(error_code: response.code, message: error_message)
context = {
code: response.code,
message: response.message,
headers: response.to_hash,
body: error_message
}
ErrorNotifier.report(exception, context: context)
end
end
end
end
end
9 changes: 1 addition & 8 deletions app/adapters/signal_adapter/outbound/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ def handle_response(response)
headers: response.to_hash,
body: error_message
}
tags = if error_message.match?(/with challenge token /)
regex = /"(.*?)"/
challenge_token = error_message.split('with challenge token ').last.match(regex).to_s.split(/"/).last
{ challenge_token: challenge_token }
else
{}
end
ErrorNotifier.report(exception, context: context, tags: tags)
ErrorNotifier.report(exception, context: context)
end
end
end
Expand Down

0 comments on commit 6f0dda1

Please sign in to comment.