Skip to content

Commit

Permalink
Simpler error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
invisiblefunnel committed May 28, 2014
1 parent 1219299 commit a2108dc
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions app/services/sms_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,10 @@ class SMSNotification < Struct.new(:phone_number, :body)
def call
client.account.messages.create(from: FROM_NUMBER, to: phone_number, body: body)
rescue Twilio::REST::RequestError => e
handle_error(e)
Rails.logger.warning("TWILIO-FAIL:#{phone_number}:#{e.message}")
end

def client
@client ||= Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN)
end

private

def handle_error(error)
log_message = if /blacklist/i === e.message
"BLACKLIST-FAIL:#{phone_number}"
else
"TWILIO-FAIL:#{phone_number}"
end

Rails.logger.warning(log_message)
end
end

0 comments on commit a2108dc

Please sign in to comment.