From 6f0dda17b35634ca70b387f00721810f07c863b8 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Wed, 13 Sep 2023 19:13:37 +0200 Subject: [PATCH] Reduce complexity by removing sentry tagging - 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. --- .../signal_adapter/bad_request_error.rb | 2 +- app/adapters/signal_adapter/outbound/file.rb | 28 +++++++++++++------ app/adapters/signal_adapter/outbound/text.rb | 9 +----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/adapters/signal_adapter/bad_request_error.rb b/app/adapters/signal_adapter/bad_request_error.rb index 11c7e7e58..6e338cdce 100644 --- a/app/adapters/signal_adapter/bad_request_error.rb +++ b/app/adapters/signal_adapter/bad_request_error.rb @@ -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 diff --git a/app/adapters/signal_adapter/outbound/file.rb b/app/adapters/signal_adapter/outbound/file.rb index 30b399aa4..610b4c610 100644 --- a/app/adapters/signal_adapter/outbound/file.rb +++ b/app/adapters/signal_adapter/outbound/file.rb @@ -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 @@ -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 diff --git a/app/adapters/signal_adapter/outbound/text.rb b/app/adapters/signal_adapter/outbound/text.rb index 97875bf94..6a994b902 100644 --- a/app/adapters/signal_adapter/outbound/text.rb +++ b/app/adapters/signal_adapter/outbound/text.rb @@ -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