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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
053196d0
Commit
053196d0
authored
Dec 13, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make bad_request! API helper more generic
All other usages of `bad_request!` already expect this to be the case.
parent
78bae25d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
13 deletions
+22
-13
changelogs/unreleased/mk-fix-bad-request-helper.yml
changelogs/unreleased/mk-fix-bad-request-helper.yml
+5
-0
ee/spec/requests/api/analytics/project_deployment_frequency_spec.rb
...quests/api/analytics/project_deployment_frequency_spec.rb
+2
-2
lib/api/concerns/packages/npm_endpoints.rb
lib/api/concerns/packages/npm_endpoints.rb
+6
-6
lib/api/go_proxy.rb
lib/api/go_proxy.rb
+1
-1
lib/api/helpers.rb
lib/api/helpers.rb
+8
-4
No files found.
changelogs/unreleased/mk-fix-bad-request-helper.yml
0 → 100644
View file @
053196d0
---
title
:
Fix wording of some 400 Bad request API responses
merge_request
:
49895
author
:
type
:
fixed
ee/spec/requests/api/analytics/project_deployment_frequency_spec.rb
View file @
053196d0
...
...
@@ -70,7 +70,7 @@ RSpec.describe API::Analytics::ProjectDeploymentFrequency do
it
'returns `bad_request` with expected message'
do
expect
(
response
.
parsed_body
).
to
eq
({
"message"
=>
"400
(Bad request)
\"
Date range is greater than 91 days
\"
not given
"
"message"
=>
"400
Bad request - Date range is greater than 91 days
"
})
end
end
...
...
@@ -82,7 +82,7 @@ RSpec.describe API::Analytics::ProjectDeploymentFrequency do
it
'returns `bad_request` with expected message'
do
expect
(
response
.
parsed_body
).
to
eq
({
"message"
=>
"400
(Bad request)
\"
Parameter `to` is before the `from` date
\"
not given
"
"message"
=>
"400
Bad request - Parameter `to` is before the `from` date
"
})
end
end
...
...
lib/api/concerns/packages/npm_endpoints.rb
View file @
053196d0
...
...
@@ -37,7 +37,7 @@ module API
get
'dist-tags'
,
format:
false
,
requirements:
::
API
::
Helpers
::
Packages
::
Npm
::
NPM_ENDPOINT_REQUIREMENTS
do
package_name
=
params
[
:package_name
]
bad_request!
(
'Package Name'
)
if
package_name
.
blank?
bad_request
_missing_attribute
!
(
'Package Name'
)
if
package_name
.
blank?
authorize_read_package!
(
project
)
...
...
@@ -62,9 +62,9 @@ module API
version
=
env
[
'api.request.body'
]
tag
=
params
[
:tag
]
bad_request!
(
'Package Name'
)
if
package_name
.
blank?
bad_request!
(
'Version'
)
if
version
.
blank?
bad_request!
(
'Tag'
)
if
tag
.
blank?
bad_request
_missing_attribute
!
(
'Package Name'
)
if
package_name
.
blank?
bad_request
_missing_attribute
!
(
'Version'
)
if
version
.
blank?
bad_request
_missing_attribute
!
(
'Tag'
)
if
tag
.
blank?
authorize_create_package!
(
project
)
...
...
@@ -85,8 +85,8 @@ module API
package_name
=
params
[
:package_name
]
tag
=
params
[
:tag
]
bad_request!
(
'Package Name'
)
if
package_name
.
blank?
bad_request!
(
'Tag'
)
if
tag
.
blank?
bad_request
_missing_attribute
!
(
'Package Name'
)
if
package_name
.
blank?
bad_request
_missing_attribute
!
(
'Tag'
)
if
tag
.
blank?
authorize_destroy_package!
(
project
)
...
...
lib/api/go_proxy.rb
View file @
053196d0
...
...
@@ -48,7 +48,7 @@ module API
not_found!
unless
Feature
.
enabled?
(
:go_proxy
,
user_project
)
module_name
=
case_decode
params
[
:module_name
]
bad_request!
(
'Module Name'
)
if
module_name
.
blank?
bad_request
_missing_attribute
!
(
'Module Name'
)
if
module_name
.
blank?
mod
=
::
Packages
::
Go
::
ModuleFinder
.
new
(
user_project
,
module_name
).
execute
...
...
lib/api/helpers.rb
View file @
053196d0
...
...
@@ -322,7 +322,7 @@ module API
# keys (required) - A hash consisting of keys that must be present
def
required_attributes!
(
keys
)
keys
.
each
do
|
key
|
bad_request!
(
key
)
unless
params
[
key
].
present?
bad_request
_missing_attribute
!
(
key
)
unless
params
[
key
].
present?
end
end
...
...
@@ -368,12 +368,16 @@ module API
render_api_error!
(
message
.
join
(
' '
),
403
)
end
def
bad_request!
(
attribute
)
message
=
[
"400 (Bad request)"
]
message
<<
"
\"
"
+
attribute
.
to_s
+
"
\"
not given"
if
attribute
def
bad_request!
(
reason
=
nil
)
message
=
[
'400 Bad request'
]
message
<<
"
-
#{
reason
}
"
if
reason
render_api_error!
(
message
.
join
(
' '
),
400
)
end
def
bad_request_missing_attribute!
(
attribute
)
bad_request!
(
"
\"
#{
attribute
}
\"
not given"
)
end
def
not_found!
(
resource
=
nil
)
message
=
[
"404"
]
message
<<
resource
if
resource
...
...
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