Add better error handling, correct the location on disk of stylesheet

This commit is contained in:
Sam 2015-05-05 23:28:19 +10:00
parent eb244bac34
commit ea670118c1
3 changed files with 8 additions and 2 deletions

View file

@ -8,7 +8,7 @@ class StylesheetsController < ApplicationController
digest = "_" + digest if digest digest = "_" + digest if digest
# Security note, safe due to route constraint # Security note, safe due to route constraint
location = "#{DiscourseStylesheets::CACHE_PATH}/#{target}#{digest}.css" location = "#{Rails.root}/#{DiscourseStylesheets::CACHE_PATH}/#{target}#{digest}.css"
unless File.exist?(location) unless File.exist?(location)
query = StylesheetCache.where(target: target) query = StylesheetCache.where(target: target)

View file

@ -20,6 +20,8 @@ class StylesheetCache < ActiveRecord::Base
success success
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
false false
rescue PG::UniqueViolation
false
end end
end end

View file

@ -89,7 +89,11 @@ class DiscourseStylesheets
File.open(stylesheet_fullpath, "w") do |f| File.open(stylesheet_fullpath, "w") do |f|
f.puts css f.puts css
end end
StylesheetCache.add(@target, digest, css) begin
StylesheetCache.add(@target, digest, css)
rescue => e
Rails.logger.warn "Completely unexpected error adding item to cache #{e}"
end
css css
end end