errors.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class ExternalDataSource
  3. module Errors
  4. class BaseError < StandardError
  5. attr_reader :external_data_source
  6. def initialize(external_data_source)
  7. @external_data_source = external_data_source
  8. super
  9. end
  10. def log_message(attribute_display, custom_message: nil)
  11. format(__('Cannot process external data source %s. %s'), attribute_display, custom_message || message)
  12. end
  13. end
  14. class NetworkError < BaseError
  15. def initialize(external_data_source, message)
  16. @message = message
  17. super(external_data_source)
  18. end
  19. attr_reader :message
  20. def log_message(attribute_display)
  21. super(attribute_display, custom_message: __('See HTTPLog for details.'))
  22. end
  23. end
  24. class SearchUrlMissingError < BaseError
  25. def message
  26. __('Search URL is missing.')
  27. end
  28. end
  29. class SearchUrlInvalidError < BaseError
  30. def message
  31. __('Search URL is invalid.')
  32. end
  33. end
  34. class ParsingError < BaseError
  35. attr_reader :parsing_path
  36. def initialize(external_data_source, path)
  37. @parsing_path = path
  38. super(external_data_source)
  39. end
  40. def self.class_for(type, location)
  41. case [type, location]
  42. in [:value, :path]
  43. ItemValuePathParsingError
  44. in [:value, :invalid]
  45. ItemValueInvalidTypeParsingError
  46. in [:label, :path]
  47. ItemLabelPathParsingError
  48. in [:label, :invalid]
  49. ItemLabelInvalidTypeParsingError
  50. end
  51. end
  52. end
  53. class ListPathParsingError < ParsingError
  54. def message
  55. format(__('Search result list key "%s" was not found.'), parsing_path)
  56. end
  57. end
  58. class ListNotArrayParsingError < ParsingError
  59. def message
  60. if parsing_path.blank?
  61. return format(__('Search result list is not an array. Please provide search result list key.'))
  62. end
  63. format(__('Search result list key "%s" is not an array.'), parsing_path)
  64. end
  65. end
  66. class ItemValuePathParsingError < ParsingError
  67. def message
  68. format(__('Search result value key "%s" was not found.'), parsing_path)
  69. end
  70. end
  71. class ItemValueInvalidTypeParsingError < ParsingError
  72. def message
  73. if parsing_path.blank?
  74. return format(__('Search result value is not a string, a number or a boolean. Please provide search result value key.'))
  75. end
  76. format(__('Search result value key "%s" is not a string, number or boolean.'), parsing_path)
  77. end
  78. end
  79. class ItemLabelPathParsingError < ParsingError
  80. def message
  81. format(__('Search result label key "%s" was not found.'), parsing_path)
  82. end
  83. end
  84. class ItemLabelInvalidTypeParsingError < ParsingError
  85. def message
  86. if parsing_path.blank?
  87. return format(__('Search result label is not a string, a number or a boolean. Please provide search result label key.'))
  88. end
  89. format(__('Search result label key "%s" is not a string, number or boolean.'), parsing_path)
  90. end
  91. end
  92. end
  93. end