From 4d4ef597dcbfc2ba5515718618f2ccc976a7cd8b Mon Sep 17 00:00:00 2001 From: James Mason Date: Mon, 8 Oct 2018 08:53:35 -0700 Subject: [PATCH] Gracefully fail out of image handling in ticket PDF (cherry picked from commit 730d53c8b642e3d04434301b4c9d4b38ef775d89) --- app/pdfs/ticket_pdf.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/pdfs/ticket_pdf.rb b/app/pdfs/ticket_pdf.rb index 834d12e2..306d5870 100644 --- a/app/pdfs/ticket_pdf.rb +++ b/app/pdfs/ticket_pdf.rb @@ -49,7 +49,11 @@ class TicketPdf < Prawn::Document if @conference.picture? conference_image = case @conference.picture.ticket.url[0, 4] when 'http', 'ftp:' # CDNs - open(@conference.picture.ticket.url) + begin + open(@conference.picture.ticket.url) + rescue OpenURI::HTTPError + nil + end when '/sys' # local storage open([ Rails.root, @@ -57,10 +61,10 @@ class TicketPdf < Prawn::Document @conference.picture.ticket.url ].join) end - image conference_image, at: [@mid_horizontal + 30, cursor] - else - image "#{Rails.root}/public/img/osem-logo.png", at: [@mid_horizontal + 30, cursor], height: 70 end + conference_image ||= open("#{Rails.root}/public/img/osem-logo.png") + image conference_image, at: [@mid_horizontal + 30, cursor], fit: [200, 70] + move_down 70 draw_text @conference.title.to_s, at: [@mid_horizontal + 30, cursor - 30], size: 12 draw_text @conference.organization.name.to_s, at: [@mid_horizontal + 30, cursor - 50], size: 12