Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
15b7b9ec
Commit
15b7b9ec
authored
Jun 20, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add rescue_from(ActionController::UnknownFormat) in Application Controller
parent
57ff9631
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
12 deletions
+50
-12
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+4
-0
app/controllers/projects/deployments_controller.rb
app/controllers/projects/deployments_controller.rb
+10
-6
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+6
-2
app/controllers/projects/prometheus_controller.rb
app/controllers/projects/prometheus_controller.rb
+0
-4
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+30
-0
No files found.
app/controllers/application_controller.rb
View file @
15b7b9ec
...
@@ -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
...
...
app/controllers/projects/deployments_controller.rb
View file @
15b7b9ec
...
@@ -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
...
...
app/controllers/projects/environments_controller.rb
View file @
15b7b9ec
...
@@ -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
...
...
app/controllers/projects/prometheus_controller.rb
View file @
15b7b9ec
...
@@ -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
...
...
spec/controllers/application_controller_spec.rb
View file @
15b7b9ec
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment