api_error.rb 810 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. class MicrosoftGraph
  3. class ApiError < StandardError
  4. attr_reader :error
  5. def initialize(error_hash)
  6. @error = error_hash.with_indifferent_access
  7. super()
  8. end
  9. def error_code
  10. error[:code] || 'no error code present'
  11. end
  12. def error_message
  13. error[:message] || 'An unknown error occurred.' # rubocop:disable Zammad/DetectTranslatableString
  14. end
  15. def request_id
  16. error.dig(:innerError, :'request-id')
  17. end
  18. def message
  19. output = "#{error_message} (#{error_code})"
  20. if request_id
  21. output += "\nMicrosoft Graph API Request ID: #{request_id}"
  22. end
  23. output
  24. end
  25. def inspect
  26. "#<#{self.class.name}: #{message.dump}>"
  27. end
  28. end
  29. end