Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

@CristinaRO
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

@CristinaRO 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
@shalott shalott merged commit a5a3482 into otwcode:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 22, 2012
  1. @CristinaRO

    Attempt at squashing the error 500 when the PDF download fails

    CristinaRO authored
    (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
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 10 deletions.
  1. +19 −10 app/controllers/downloads_controller.rb
View
29 app/controllers/downloads_controller.rb
@@ -22,7 +22,7 @@ def show
if @work.unrevealed?
flash[:error] = ts("Sorry, you can't download an unrevealed work")
- redirect_back_or_default works_path
+ redirect_back_or_default works_path and return
end
Rails.logger.debug "Work basename: #{@work.download_basename}"
@@ -58,8 +58,11 @@ def download_pdf
Rails.logger.debug cmd
`#{cmd} 2> /dev/null`
- # send as PDF
- check_for_file("pdf")
+ # send as PDF, if file exists, or flash error and redirect
+ unless check_for_file("pdf")
+ flash[:error] = ts('We were not able to render this work. Please try another format')
+ redirect_back_or_default work_path(@work) and return
+ end
send_file("#{@work.download_basename}.pdf", :type => "application/pdf")
end
@@ -90,7 +93,12 @@ def download_mobi
end
Rails.logger.debug cmd
`#{cmd} 2> /dev/null`
- check_for_file("mobi")
+
+ # send as mobi, if file exists, or flash error and redirect
+ unless check_for_file("mobi")
+ flash[:error] = ts('We were not able to render this work. Please try another format')
+ redirect_back_or_default work_path(@work) and return
+ end
send_file("#{@work.download_basename}.mobi", :type => "application/mobi")
end
@@ -107,16 +115,17 @@ def download_epub
Rails.logger.debug cmd
`#{cmd} 2> /dev/null`
- # send the file
- check_for_file("epub")
+ # send as epub, if file exists, or flash error and redirect
+ unless check_for_file("epub")
+ flash[:error] = ts('We were not able to render this work. Please try another format')
+ redirect_back_or_default work_path(@work) and return
+ end
send_file("#{@work.download_basename}.epub", :type => "application/epub")
end
+ # redirect and return inside this method would only exit *this* method, not the controller action it was called from
def check_for_file(format)
- unless File.exists?("#{@work.download_basename}.#{format}")
- flash[:error] = ts('We were not able to render this work. Please try another format')
- redirect_back_or_default work_path(@work) and return
- end
+ File.exists?("#{@work.download_basename}.#{format}")
end
def create_work_html
Something went wrong with that request. Please try again.