mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 04:27:56 +08:00
FIX: return an empty result if response from Amazon is missing expected attributes (#13173)
* FIX: return an empty result if response from Amazon is missing attributes Check we have the basic attributes requires to construct a Onebox for Amazon. This is an attempt to handle scenarios where we receive a valid 200-status response from an Amazon request that does not include the data we’re expecting. * Update lib/onebox/engine/amazon_onebox.rb Co-authored-by: Régis Hanol <regis@hanol.fr> Co-authored-by: Régis Hanol <regis@hanol.fr>
This commit is contained in:
@ -66,6 +66,10 @@ module Onebox
|
||||
to_html
|
||||
end
|
||||
|
||||
def verified_data
|
||||
data
|
||||
end
|
||||
|
||||
def data
|
||||
@data ||= begin
|
||||
html_entities = HTMLEntities.new
|
||||
|
@ -46,6 +46,37 @@ module Onebox
|
||||
end
|
||||
end
|
||||
|
||||
def to_html(ignore_errors = false)
|
||||
unless ignore_errors
|
||||
verified_data # forces a check for missing fields
|
||||
return '' unless errors.empty?
|
||||
end
|
||||
|
||||
super()
|
||||
end
|
||||
|
||||
def placeholder_html
|
||||
to_html(true)
|
||||
end
|
||||
|
||||
def verified_data
|
||||
@verified_data ||= begin
|
||||
result = data
|
||||
|
||||
required_tags = [:title, :description]
|
||||
required_tags.each do |tag|
|
||||
if result[tag].blank?
|
||||
errors[tag] ||= []
|
||||
errors[tag] << 'is blank'
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
@verified_data
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def has_cached_body
|
||||
|
@ -40,6 +40,11 @@ module Onebox
|
||||
engine.data
|
||||
end
|
||||
|
||||
def verified_data
|
||||
return {} unless engine
|
||||
engine.verified_data
|
||||
end
|
||||
|
||||
def options
|
||||
OpenStruct.new(@options)
|
||||
end
|
||||
|
Reference in New Issue
Block a user