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 ...@@ -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,6 +25,8 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -25,6 +25,8 @@ 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?
respond_to do |format|
format.json do
metrics = deployment.additional_metrics metrics = deployment.additional_metrics
if metrics.any? if metrics.any?
...@@ -33,6 +35,8 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -33,6 +35,8 @@ class Projects::DeploymentsController < Projects::ApplicationController
head :no_content head :no_content
end end
end end
end
end
private private
......
...@@ -132,10 +132,14 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -132,10 +132,14 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
def additional_metrics def additional_metrics
respond_to do |format|
format.json do
additional_metrics = environment.additional_metrics || {} 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 ...@@ -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 ...@@ -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
......
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