Skip to content
Snippets Groups Projects
Commit 15b7b9ec authored by Pawel Chojnacki's avatar Pawel Chojnacki
Browse files

Add rescue_from(ActionController::UnknownFormat) in Application Controller

parent 57ff9631
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment