mirror of
https://github.com/discourse/discourse.git
synced 2025-04-19 09:39:08 +08:00
Allow NotFound
to specify an optional Location
for the resource
This commit is contained in:
parent
367fb1c524
commit
4ae66c9e01
@ -136,7 +136,15 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue_from Discourse::NotFound, PluginDisabled do
|
rescue_from Discourse::NotFound do |e|
|
||||||
|
rescue_discourse_actions(
|
||||||
|
:not_found,
|
||||||
|
404,
|
||||||
|
location: e.location
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
rescue_from PluginDisabled do |e|
|
||||||
rescue_discourse_actions(:not_found, 404)
|
rescue_discourse_actions(:not_found, 404)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -159,10 +167,18 @@ class ApplicationController < ActionController::Base
|
|||||||
(request.xhr?) ||
|
(request.xhr?) ||
|
||||||
((params[:external_id] || '').ends_with? '.json')
|
((params[:external_id] || '').ends_with? '.json')
|
||||||
|
|
||||||
|
if opts[:location]
|
||||||
|
response.headers['Location'] = opts[:location]
|
||||||
|
end
|
||||||
|
|
||||||
if show_json_errors
|
if show_json_errors
|
||||||
# HACK: do not use render_json_error for topics#show
|
# HACK: do not use render_json_error for topics#show
|
||||||
if request.params[:controller] == 'topics' && request.params[:action] == 'show'
|
if request.params[:controller] == 'topics' && request.params[:action] == 'show'
|
||||||
return render status: status_code, layout: false, text: (status_code == 404 || status_code == 410) ? build_not_found_page(status_code) : I18n.t(type)
|
return render(
|
||||||
|
status: status_code,
|
||||||
|
layout: false,
|
||||||
|
text: (status_code == 404 || status_code == 410) ? build_not_found_page(status_code) : I18n.t(type)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
render_json_error I18n.t(opts[:custom_message] || type), type: type, status: status_code
|
render_json_error I18n.t(opts[:custom_message] || type), type: type, status: status_code
|
||||||
|
@ -74,7 +74,13 @@ module Discourse
|
|||||||
end
|
end
|
||||||
|
|
||||||
# When something they want is not found
|
# When something they want is not found
|
||||||
class NotFound < StandardError; end
|
class NotFound < StandardError
|
||||||
|
attr_reader :location
|
||||||
|
def initialize(opts = nil)
|
||||||
|
opts ||= {}
|
||||||
|
@location = opts[:location]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# When a setting is missing
|
# When a setting is missing
|
||||||
class SiteSettingMissing < StandardError; end
|
class SiteSettingMissing < StandardError; end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user