Commit 15b7b9ec authored by Pawel Chojnacki's avatar Pawel Chojnacki

Add rescue_from(ActionController::UnknownFormat) in Application Controller

parent 57ff9631
......@@ -40,6 +40,10 @@ class ApplicationController < ActionController::Base
render_404
end
rescue_from(ActionController::UnknownFormat) do
render_404
end
rescue_from Gitlab::Access::AccessDeniedError do |exception|
render_403
end
......
......@@ -25,12 +25,16 @@ class Projects::DeploymentsController < Projects::ApplicationController
def additional_metrics
return render_404 unless deployment.has_additional_metrics?
metrics = deployment.additional_metrics
if metrics.any?
render json: metrics
else
head :no_content
respond_to do |format|
format.json do
metrics = deployment.additional_metrics
if metrics.any?
render json: metrics
else
head :no_content
end
end
end
end
......
......@@ -132,9 +132,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
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
private
......
......@@ -18,10 +18,6 @@ class Projects::PrometheusController < Projects::ApplicationController
private
rescue_from(ActionController::UnknownFormat) do
render_404
end
def require_prometheus_metrics!
render_404 unless project.prometheus_service.present?
end
......
......@@ -99,6 +99,36 @@ describe ApplicationController do
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 "authenticating a user from an RSS token" do
controller(described_class) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment