message_enricher.rb 578 B

1234567891011121314151617181920212223
  1. module ShopifyAPI
  2. class MessageEnricher < SimpleDelegator
  3. def message
  4. return super unless (400...500).include?(code.to_i)
  5. @_cached_message ||= begin
  6. detailed_error = begin
  7. parsed_body = JSON.parse(body)
  8. if parsed_body['error']
  9. parsed_body['error'].to_s
  10. elsif parsed_body['errors']
  11. Array(parsed_body['errors']).join('; ')
  12. end
  13. rescue JSON::ParserError
  14. nil
  15. end
  16. detailed_error.present? ? "#{super} (#{detailed_error})" : super
  17. end
  18. end
  19. end
  20. end