Add rescue_from(ActionController::UnknownFormat) in Application Controller
This commit is contained in:
parent
57ff963129
commit
15b7b9ec41
|
@ -40,6 +40,10 @@ class ApplicationController < ActionController::Base
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue_from(ActionController::UnknownFormat) do
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
rescue_from Gitlab::Access::AccessDeniedError do |exception|
|
rescue_from Gitlab::Access::AccessDeniedError do |exception|
|
||||||
render_403
|
render_403
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,12 +25,16 @@ class Projects::DeploymentsController < Projects::ApplicationController
|
||||||
def additional_metrics
|
def additional_metrics
|
||||||
return render_404 unless deployment.has_additional_metrics?
|
return render_404 unless deployment.has_additional_metrics?
|
||||||
|
|
||||||
metrics = deployment.additional_metrics
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
metrics = deployment.additional_metrics
|
||||||
|
|
||||||
if metrics.any?
|
if metrics.any?
|
||||||
render json: metrics
|
render json: metrics
|
||||||
else
|
else
|
||||||
head :no_content
|
head :no_content
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -132,9 +132,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def additional_metrics
|
def additional_metrics
|
||||||
additional_metrics = environment.additional_metrics || {}
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
additional_metrics = environment.additional_metrics || {}
|
||||||
|
|
||||||
render json: additional_metrics, status: additional_metrics.any? ? :ok : :no_content
|
render json: additional_metrics, status: additional_metrics.any? ? :ok : :no_content
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -18,10 +18,6 @@ class Projects::PrometheusController < Projects::ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
rescue_from(ActionController::UnknownFormat) do
|
|
||||||
render_404
|
|
||||||
end
|
|
||||||
|
|
||||||
def require_prometheus_metrics!
|
def require_prometheus_metrics!
|
||||||
render_404 unless project.prometheus_service.present?
|
render_404 unless project.prometheus_service.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,6 +99,36 @@ describe ApplicationController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'response format' do
|
||||||
|
controller(described_class) do
|
||||||
|
def index
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when format is handled' do
|
||||||
|
let(:requested_format) { :json }
|
||||||
|
|
||||||
|
it 'returns 200 response' do
|
||||||
|
get :index, private_token: user.private_token, format: requested_format
|
||||||
|
|
||||||
|
expect(response).to have_http_status 200
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when format is not handled' do
|
||||||
|
it 'returns 404 response' do
|
||||||
|
get :index, private_token: user.private_token
|
||||||
|
|
||||||
|
expect(response).to have_http_status 404
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#authenticate_user_from_rss_token' do
|
describe '#authenticate_user_from_rss_token' do
|
||||||
describe "authenticating a user from an RSS token" do
|
describe "authenticating a user from an RSS token" do
|
||||||
controller(described_class) do
|
controller(described_class) do
|
||||||
|
|
Loading…
Reference in New Issue