Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-web-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
tools
python-web-common
Commits
09fe6ddd
Commit
09fe6ddd
authored
4 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Make BadRequestErrors more verbose
parent
e4c5bcc2
No related branches found
No related tags found
1 merge request
!2
Make BadRequestErrors more verbose
Pipeline
#11753
passed
4 years ago
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ai_web_common/rpc/core.py
+10
-5
10 additions, 5 deletions
ai_web_common/rpc/core.py
with
10 additions
and
5 deletions
ai_web_common/rpc/core.py
+
10
−
5
View file @
09fe6ddd
...
@@ -27,11 +27,14 @@ HTTP_STATUS_CODE = attributes_helper.COMMON_ATTRIBUTES['HTTP_STATUS_CODE']
...
@@ -27,11 +27,14 @@ HTTP_STATUS_CODE = attributes_helper.COMMON_ATTRIBUTES['HTTP_STATUS_CODE']
class
StatusError
(
Exception
):
class
StatusError
(
Exception
):
def
__init__
(
self
,
url
,
resp
):
def
__init__
(
self
,
url
,
resp
,
extra_msg
=
None
):
self
.
url
=
url
.
url
self
.
url
=
url
.
url
self
.
code
=
resp
.
status
self
.
code
=
resp
.
status
super
(
StatusError
,
self
).
__init__
(
'
%s: HTTP error %d: %s
'
%
(
msg
=
'
%s: HTTP error %d: %s
'
%
(
self
.
url
,
self
.
code
,
resp
.
reason
)
self
.
url
,
self
.
code
,
resp
.
reason
))
if
extra_msg
:
msg
+=
'
'
msg
+=
extra_msg
super
(
StatusError
,
self
).
__init__
(
msg
)
class
RetriableStatusError
(
StatusError
):
class
RetriableStatusError
(
StatusError
):
...
@@ -41,16 +44,18 @@ class RetriableStatusError(StatusError):
...
@@ -41,16 +44,18 @@ class RetriableStatusError(StatusError):
class
BadRequestError
(
StatusError
):
class
BadRequestError
(
StatusError
):
def
__init__
(
self
,
url
,
resp
):
def
__init__
(
self
,
url
,
resp
):
super
(
BadRequestError
,
self
).
__init__
(
url
,
resp
)
# Some backends return structured 400 errors with a
# Some backends return structured 400 errors with a
# JSON-encoded body containing field-level validation
# JSON-encoded body containing field-level validation
# errors. Detect this and make it available in the 'errors'
# errors. Detect this and make it available in the 'errors'
# attribute of the exception object.
# attribute of the exception object.
try
:
try
:
self
.
errors
=
_json_response_decoder
(
resp
)
self
.
errors
=
_json_response_decoder
(
resp
)
msg
=
json
.
dumps
(
self
.
errors
)
except
ValueError
:
except
ValueError
:
self
.
errors
=
{}
self
.
errors
=
{}
msg
=
None
super
(
BadRequestError
,
self
).
__init__
(
url
,
resp
,
extra_msg
=
msg
)
class
AuthenticationError
(
StatusError
):
class
AuthenticationError
(
StatusError
):
...
...
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