FIX: Display json response when `Discourse::InvalidAccess` is raised for
non json requests.
This commit is contained in:
parent
373fd8990e
commit
5f1c29e424
|
@ -157,7 +157,8 @@ class ApplicationController < ActionController::Base
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
show_json_errors = (request.format && request.format.json?) ||
|
show_json_errors = (request.format && request.format.json?) ||
|
||||||
(request.xhr?) ||
|
(request.xhr?) ||
|
||||||
((params[:external_id] || '').ends_with? '.json')
|
((params[:external_id] || '').ends_with? '.json') ||
|
||||||
|
!(current_user rescue nil)
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -1064,6 +1064,14 @@ describe TopicsController do
|
||||||
}, format: :json
|
}, format: :json
|
||||||
|
|
||||||
expect(response.code.to_i).to be(403)
|
expect(response.code.to_i).to be(403)
|
||||||
|
expect(response.body).to eq(I18n.t("invalid_access"))
|
||||||
|
|
||||||
|
get :show, params: {
|
||||||
|
topic_id: topic.id, slug: topic.slug, api_key: "bad"
|
||||||
|
}, format: :html
|
||||||
|
|
||||||
|
expect(response.code.to_i).to be(403)
|
||||||
|
expect(response.body).to eq(I18n.t("invalid_access"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue