From 42714b424f09f7bd32606f125f5a513fc25f1e19 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 30 May 2013 14:46:02 -0400 Subject: [PATCH] For 403 errors, show the same html page as 404 --- app/controllers/application_controller.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 37d53f3c55c..30fe6513c0f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -69,18 +69,17 @@ class ApplicationController < ActionController::Base if request.format && request.format.json? render status: 404, layout: false, text: "[error: 'not found']" else - f = Topic.where(deleted_at: nil, archetype: "regular") - @latest = f.order('views desc').take(10) - @recent = f.order('created_at desc').take(10) - @slug = params[:slug].class == String ? params[:slug] : '' - @slug.gsub!('-',' ') - render status: 404, layout: 'no_js', template: '/exceptions/not_found' + render_not_found_page(404) end end rescue_from Discourse::InvalidAccess do - render file: 'public/403', formats: [:html], layout: false, status: 403 + if request.format && request.format.json? + render status: 403, layout: false, text: "[error: 'invalid access']" + else + render_not_found_page(403) + end end @@ -279,4 +278,13 @@ class ApplicationController < ActionController::Base raise Discourse::NotLoggedIn.new unless current_user.present? end + def render_not_found_page(status=404) + f = Topic.where(deleted_at: nil, archetype: "regular") + @latest = f.order('views desc').take(10) + @recent = f.order('created_at desc').take(10) + @slug = params[:slug].class == String ? params[:slug] : '' + @slug.gsub!('-',' ') + render status: status, layout: 'no_js', template: '/exceptions/not_found' + end + end