mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
For 403 errors, show the same html page as 404
This commit is contained in:
@ -69,18 +69,17 @@ class ApplicationController < ActionController::Base
|
|||||||
if request.format && request.format.json?
|
if request.format && request.format.json?
|
||||||
render status: 404, layout: false, text: "[error: 'not found']"
|
render status: 404, layout: false, text: "[error: 'not found']"
|
||||||
else
|
else
|
||||||
f = Topic.where(deleted_at: nil, archetype: "regular")
|
render_not_found_page(404)
|
||||||
@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'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::InvalidAccess do
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -279,4 +278,13 @@ class ApplicationController < ActionController::Base
|
|||||||
raise Discourse::NotLoggedIn.new unless current_user.present?
|
raise Discourse::NotLoggedIn.new unless current_user.present?
|
||||||
end
|
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
|
end
|
||||||
|
Reference in New Issue
Block a user