Skip to content

Commit

Permalink
Support iTexmo complex errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matiasgarciaisaia committed Jul 16, 2024
1 parent b002323 commit 04d19fa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/itexmo/send_itexmo_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand All @@ -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}"))

Expand Down

0 comments on commit 04d19fa

Please sign in to comment.