handles_error.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Whatsapp::Webhook
  3. module Concerns::HandlesError
  4. private
  5. def error
  6. raise NotImplementedError
  7. end
  8. def handle_error
  9. # https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes
  10. #
  11. # Log any error status to the Rails log. Update the channel status on
  12. # any unrecoverable error - errors that need action from an administator
  13. # and block the channel from sending or receiving messages.
  14. Rails.logger.error "WhatsApp channel (#{@channel.options[:callback_url_uuid]}) - failed message: #{error[:title]} (#{error[:code]})"
  15. recoverable_errors = [
  16. 130_472, # User's number is part of an experiment'
  17. 131_021, # Recipient cannot be sender'
  18. 131_026, # Message undeliverable'
  19. 131_047, # Re-engagement message
  20. 131_052, # Media download error'
  21. 131_053 # Media upload error'
  22. ]
  23. return if recoverable_errors.include?(error[:code])
  24. @channel.update!(
  25. status_out: 'error',
  26. last_log_out: "#{error[:title]} (#{error[:code]})",
  27. )
  28. end
  29. end
  30. end