From 26a7bf0c91f0b1c81f9dd0293898ece62fa2681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Garc=C3=ADa=20Isa=C3=ADa?= Date: Tue, 16 Jul 2024 15:43:32 -0300 Subject: [PATCH] Support iTexmo complex errors (#109) iTexmo API is sending a map instead of a simple string for some errors. We were previously failing to handle them. We now support those, even if they seem to be an issue in their API. See #107 --- app/models/itexmo/send_itexmo_message_job.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/itexmo/send_itexmo_message_job.rb b/app/models/itexmo/send_itexmo_message_job.rb index 0966a9fe..17ae9842 100644 --- a/app/models/itexmo/send_itexmo_message_job.rb +++ b/app/models/itexmo/send_itexmo_message_job.rb @@ -44,7 +44,12 @@ def managed_perform rescue RestClient::BadRequest => e response = JSON.parse e.response - case response['Message'].downcase + response_message = response['Message'] + # iTexmo API is returning the error message wrapped in a new hash for some cases + # (probably a bug on their API, but here we are) + response_message = response_message['Message'].first if response_message.is_a? Hash + + case response_message.downcase when 'itexmo email is required.', 'itexmo password is required.', 'itexmo email and password is required.', @@ -63,6 +68,7 @@ def managed_perform when 'invalid number.', 'maximum allowed characters for message reached.', + 'the message field is required.', /allowed maximum length for otp is .*\. you are trying to send a message with .* characters\./ raise MessageException.new(Exception.new("Received message error for AO #{@msg.id}: #{e.class} (#{e.message}) - #{e.response}"))