mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Remove code duplication in ApplicationController
This commit is contained in:
@ -66,23 +66,20 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::NotFound do
|
rescue_from Discourse::NotFound do
|
||||||
|
rescue_discourse_actions("[error: 'not found']", 404)
|
||||||
if request.format && request.format.json?
|
|
||||||
render status: 404, layout: false, text: "[error: 'not found']"
|
|
||||||
else
|
|
||||||
render_not_found_page(404)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::InvalidAccess do
|
rescue_from Discourse::InvalidAccess do
|
||||||
if request.format && request.format.json?
|
rescue_discourse_actions("[error: 'invalid access']", 403)
|
||||||
render status: 403, layout: false, text: "[error: 'invalid access']"
|
|
||||||
else
|
|
||||||
render_not_found_page(403)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rescue_discourse_actions(message, error)
|
||||||
|
if request.format && request.format.json?
|
||||||
|
render status: error, layout: false, text: message
|
||||||
|
else
|
||||||
|
render_not_found_page(error)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def set_locale
|
def set_locale
|
||||||
I18n.locale = SiteSetting.default_locale
|
I18n.locale = SiteSetting.default_locale
|
||||||
|
Reference in New Issue
Block a user