I want to rescue every 403 response from S3 in my app. They're mostly in image tags, breaking the image in the view. How can I do that in ApplicationController
when the image tags don't raise exceptions, they just have broken images in the view?
rescue_from ??? do |e|
logger.debug "broken image: #{e}"
end
Some images are rendered in a helper like so:
def user_image(img_style)
"<img src='#{asset.image(img_style)}' />"
end
Where asset.image(img_style)
returns a (in this case forbidden) URL.
Others are just like:
<%= image_tag document.other_asset.image(:small) %>
There's no single parent controller (save ApplicationController
) I guess.
There is, however, a single polymorphic class (ImageAttachment
) that stores the image. Should I fetch it in the model beforehand and raise the error? Doesn't that involve making the request twice?