Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
software-di-controllo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Davide Ricci
software-di-controllo
Commits
f5385fce
Commit
f5385fce
authored
1 month ago
by
vertighel
Browse files
Options
Downloads
Patches
Plain Diff
Managing http errors in request
parent
dd35e2de
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#29520
passed
1 month ago
Stage: setup_and_format
Stage: lint
Stage: auto_commit
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
noctua/utils/check.py
+25
-10
25 additions, 10 deletions
noctua/utils/check.py
with
25 additions
and
10 deletions
noctua/utils/check.py
+
25
−
10
View file @
f5385fce
...
...
@@ -55,7 +55,6 @@ def content_errors(content):
return
content_errors_inner
def
request_errors
(
func
):
'''
Decorator for handling exceptions on a class method.
...
...
@@ -78,17 +77,33 @@ def request_errors(func):
res
=
e
.
response
if
res
.
status_code
==
400
:
# '0x80001005\r\nThe Error Message\r\n'
msg
=
f
"
{
name
}
: Device error
"
# API returns body like: '0x8000100a\r\nParameter(s) missing.\r\n'
try
:
# Attempt to parse the API-specific error
body_lines
=
res
.
text
.
strip
().
split
(
'
\r\n
'
)
error_code
=
body_lines
[
0
]
error_message
=
body_lines
[
1
]
if
len
(
body_lines
)
>
1
else
"
No error message provided.
"
msg
=
f
"
{
name
}
: Bad Request - API Error
{
error_code
}
:
{
error_message
}
"
log
.
error
(
msg
)
this
.
error
.
append
(
res
.
text
.
replace
(
"
\r\n
"
,
"
"
))
this
.
error
.
append
(
msg
)
except
(
IndexError
,
AttributeError
):
# Fallback for unexpected 400 error format
msg
=
f
"
{
name
}
: Bad Request with unparsable body.
"
log
.
error
(
msg
)
log
.
error
(
f
"
Raw response:
{
res
.
text
}
"
)
this
.
error
.
append
(
msg
)
elif
res
.
status_code
==
500
:
log
.
error
(
res
.
reason
)
# Device error
log
.
error
(
res
.
text
)
this
.
error
.
append
(
res
.
reason
)
msg
=
f
"
{
name
}
: Internal Server Error on device.
"
log
.
error
(
msg
)
log
.
error
(
f
"
Reason:
{
res
.
reason
}
"
)
log
.
error
(
f
"
Response:
{
res
.
text
}
"
)
this
.
error
.
append
(
msg
)
this
.
error
.
append
(
res
.
text
)
else
:
# 404
log
.
error
(
e
)
# Not found
else
:
# 404 Not Found, etc.
msg
=
f
"
{
name
}
: HTTP Error -
{
e
}
"
log
.
error
(
msg
)
this
.
error
.
append
(
str
(
e
))
return
...
...
This diff is collapsed.
Click to expand it.
Davide Ricci
@davide.ricci
mentioned in commit
76753c0b
·
1 month ago
mentioned in commit
76753c0b
mentioned in commit 76753c0bf604410b3fc717474c6fa5bb8e58081c
Toggle commit list
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