Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
1505e40c
Unverified
Commit
1505e40c
authored
7 years ago
by
Harsha Kethineni
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1002 from scitran/err-request-id
Error response contains request id
parents
bbcbe7d9
990bec8f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/util.py
+5
-4
5 additions, 4 deletions
api/util.py
api/web/base.py
+3
-2
3 additions, 2 deletions
api/web/base.py
api/web/start.py
+2
-2
2 additions, 2 deletions
api/web/start.py
tests/integration_tests/python/test_errors.py
+20
-0
20 additions, 0 deletions
tests/integration_tests/python/test_errors.py
with
30 additions
and
8 deletions
api/util.py
+
5
−
4
View file @
1505e40c
...
...
@@ -204,19 +204,20 @@ def format_hash(hash_alg, hash_):
return
'
-
'
.
join
((
'
v0
'
,
hash_alg
,
hash_
))
def
create_json_http_exception_response
(
message
,
code
,
custom
=
None
):
def
create_json_http_exception_response
(
message
,
code
,
request_id
,
custom
=
None
):
content
=
{
'
message
'
:
message
,
'
status_code
'
:
code
'
status_code
'
:
code
,
'
request_id
'
:
request_id
}
if
custom
:
content
.
update
(
custom
)
return
content
def
send_json_http_exception
(
response
,
message
,
code
,
custom
=
None
):
def
send_json_http_exception
(
response
,
message
,
code
,
request_id
,
custom
=
None
):
response
.
set_status
(
code
)
json_content
=
json
.
dumps
(
create_json_http_exception_response
(
message
,
code
,
custom
))
json_content
=
json
.
dumps
(
create_json_http_exception_response
(
message
,
code
,
request_id
,
custom
))
response
.
headers
[
'
Content-Type
'
]
=
'
application/json; charset=utf-8
'
response
.
write
(
json_content
)
...
...
This diff is collapsed.
Click to expand it.
api/web/base.py
+
3
−
2
View file @
1505e40c
...
...
@@ -328,6 +328,7 @@ class RequestHandler(webapp2.RequestHandler):
For all others use a generic 500 error code and log the stack trace
"""
request_id
=
self
.
request
.
id
custom_errors
=
None
message
=
str
(
exception
)
if
isinstance
(
exception
,
webapp2
.
HTTPException
):
...
...
@@ -369,9 +370,9 @@ class RequestHandler(webapp2.RequestHandler):
self
.
request
.
logger
.
error
(
tb
)
if
return_json
:
return
util
.
create_json_http_exception_response
(
message
,
code
,
custom
=
custom_errors
)
return
util
.
create_json_http_exception_response
(
message
,
code
,
request_id
,
custom
=
custom_errors
)
util
.
send_json_http_exception
(
self
.
response
,
message
,
code
,
custom
=
custom_errors
)
util
.
send_json_http_exception
(
self
.
response
,
message
,
code
,
request_id
,
custom
=
custom_errors
)
def
log_user_access
(
self
,
access_type
,
cont_name
=
None
,
cont_id
=
None
,
multifile
=
False
):
...
...
This diff is collapsed.
Click to expand it.
api/web/start.py
+
2
−
2
View file @
1505e40c
...
...
@@ -50,14 +50,14 @@ def dispatcher(router, request, response):
response
.
write
(
json
.
dumps
(
rv
,
default
=
encoder
.
custom_json_serializer
))
response
.
headers
[
'
Content-Type
'
]
=
'
application/json; charset=utf-8
'
except
webapp2
.
HTTPException
as
e
:
util
.
send_json_http_exception
(
response
,
str
(
e
),
e
.
code
)
util
.
send_json_http_exception
(
response
,
str
(
e
),
e
.
code
,
request
.
id
)
except
Exception
as
e
:
# pylint: disable=broad-except
request
.
logger
.
error
(
"
Error dispatching request
"
,
exc_info
=
True
)
if
config
.
get_item
(
'
core
'
,
'
debug
'
):
message
=
traceback
.
format_exc
()
else
:
message
=
'
Internal Server Error
'
util
.
send_json_http_exception
(
response
,
message
,
500
)
util
.
send_json_http_exception
(
response
,
message
,
500
,
request
.
id
)
def
app_factory
(
*
_
,
**
__
):
# pylint: disable=protected-access,unused-argument
...
...
This diff is collapsed.
Click to expand it.
tests/integration_tests/python/test_errors.py
+
20
−
0
View file @
1505e40c
...
...
@@ -12,3 +12,23 @@ def test_extra_param(as_admin):
r
=
as_admin
.
get
(
'
/projects
'
)
assert
r
.
ok
assert
not
any
(
project
[
'
label
'
]
==
label
for
project
in
r
.
json
())
def
test_error_response
(
as_admin
,
as_user
,
as_public
,
data_builder
):
group
=
data_builder
.
create_group
()
project
=
data_builder
.
create_project
()
# Test dao exception
r
=
as_admin
.
post
(
'
/users
'
,
json
=
{
'
_id
'
:
"
admin@user.com
"
,
'
firstname
'
:
"
Firstname
"
,
'
lastname
'
:
"
Lastname
"
})
assert
r
.
status_code
==
409
assert
r
.
json
().
get
(
'
request_id
'
)
# Test schema exceptions
r
=
as_admin
.
post
(
'
/groups
'
,
json
=
{
'
foo
'
:
'
bar
'
})
assert
r
.
status_code
==
400
assert
r
.
json
().
get
(
'
request_id
'
)
# Test Permission exception
r
=
as_user
.
put
(
'
/projects/
'
+
project
,
json
=
{
'
label
'
:
'
Project
'
})
assert
r
.
status_code
==
403
assert
r
.
json
().
get
(
'
request_id
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment