Skip to content
This repository

Attempt at squashing the error 500 when the PDF download fails #590

Merged
merged 1 commit into from about 2 years ago

2 participants

Cristina astolat
Cristina
Collaborator

(Not a fix for why it doesn't get created, that one is way above my head)

This is just http://code.google.com/p/otwarchive/issues/detail?id=3024

Cristina CristinaRO Attempt at squashing the error 500 when the PDF download fails
(Not a fix for *why* it doesn't get created, that one is way above my
head)

This is just http://code.google.com/p/otwarchive/issues/detail?id=3024
08984d0
astolat shalott merged commit a5a3482 into from
astolat shalott closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 22, 2012
Cristina CristinaRO Attempt at squashing the error 500 when the PDF download fails
(Not a fix for *why* it doesn't get created, that one is way above my
head)

This is just http://code.google.com/p/otwarchive/issues/detail?id=3024
08984d0
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 19 additions and 10 deletions. Show diff stats Hide diff stats

  1. +19 10 app/controllers/downloads_controller.rb
29 app/controllers/downloads_controller.rb
@@ -22,7 +22,7 @@ def show
22 22
23 23 if @work.unrevealed?
24 24 flash[:error] = ts("Sorry, you can't download an unrevealed work")
25   - redirect_back_or_default works_path
  25 + redirect_back_or_default works_path and return
26 26 end
27 27
28 28 Rails.logger.debug "Work basename: #{@work.download_basename}"
@@ -58,8 +58,11 @@ def download_pdf
58 58 Rails.logger.debug cmd
59 59 `#{cmd} 2> /dev/null`
60 60
61   - # send as PDF
62   - check_for_file("pdf")
  61 + # send as PDF, if file exists, or flash error and redirect
  62 + unless check_for_file("pdf")
  63 + flash[:error] = ts('We were not able to render this work. Please try another format')
  64 + redirect_back_or_default work_path(@work) and return
  65 + end
63 66 send_file("#{@work.download_basename}.pdf", :type => "application/pdf")
64 67 end
65 68
@@ -90,7 +93,12 @@ def download_mobi
90 93 end
91 94 Rails.logger.debug cmd
92 95 `#{cmd} 2> /dev/null`
93   - check_for_file("mobi")
  96 +
  97 + # send as mobi, if file exists, or flash error and redirect
  98 + unless check_for_file("mobi")
  99 + flash[:error] = ts('We were not able to render this work. Please try another format')
  100 + redirect_back_or_default work_path(@work) and return
  101 + end
94 102 send_file("#{@work.download_basename}.mobi", :type => "application/mobi")
95 103 end
96 104
@@ -107,16 +115,17 @@ def download_epub
107 115 Rails.logger.debug cmd
108 116 `#{cmd} 2> /dev/null`
109 117
110   - # send the file
111   - check_for_file("epub")
  118 + # send as epub, if file exists, or flash error and redirect
  119 + unless check_for_file("epub")
  120 + flash[:error] = ts('We were not able to render this work. Please try another format')
  121 + redirect_back_or_default work_path(@work) and return
  122 + end
112 123 send_file("#{@work.download_basename}.epub", :type => "application/epub")
113 124 end
114 125
  126 + # redirect and return inside this method would only exit *this* method, not the controller action it was called from
115 127 def check_for_file(format)
116   - unless File.exists?("#{@work.download_basename}.#{format}")
117   - flash[:error] = ts('We were not able to render this work. Please try another format')
118   - redirect_back_or_default work_path(@work) and return
119   - end
  128 + File.exists?("#{@work.download_basename}.#{format}")
120 129 end
121 130
122 131 def create_work_html

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.