Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
slapos.core
Commits
1fc08717
Commit
1fc08717
authored
May 15, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse and display error messages from server (GET and POST).
parent
421c8876
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
slapos/slap/slap.py
slapos/slap/slap.py
+21
-4
No files found.
slapos/slap/slap.py
View file @
1fc08717
...
...
@@ -36,12 +36,14 @@ __all__ = ["slap", "ComputerPartition", "Computer", "SoftwareRelease",
import
httplib
import
logging
import
re
import
socket
import
ssl
import
traceback
import
urllib
import
urlparse
from
xml.sax
import
saxutils
import
zope.interface
from
interface
import
slap
as
interface
from
xml_marshaller
import
xml_marshaller
...
...
@@ -339,6 +341,19 @@ class Computer(SlapDocument):
return
xml_marshaller
.
loads
(
xml
)
def
parsed_error_message
(
status
,
body
,
path
):
m
=
re
.
search
(
'(Error Value:
\
n
.*)'
,
body
,
re
.
MULTILINE
)
if
m
:
match
=
' '
.
join
(
line
.
strip
()
for
line
in
m
.
group
(
0
).
split
(
'
\
n
'
))
return
'%s (status %s while calling %s)'
%
(
saxutils
.
unescape
(
match
),
status
,
path
)
else
:
return
'Server responded with wrong code %s with %s'
%
(
status
,
path
)
class
ComputerPartition
(
SlapRequester
):
zope
.
interface
.
implements
(
interface
.
IComputerPartition
)
...
...
@@ -594,8 +609,9 @@ class ConnectionHelper:
elif
self
.
response
.
status
==
httplib
.
FORBIDDEN
:
raise
Unauthorized
(
path
)
elif
self
.
response
.
status
!=
httplib
.
OK
:
message
=
'Server responded with wrong code %s with %s'
%
\
(
self
.
response
.
status
,
path
)
message
=
parsed_error_message
(
self
.
response
.
status
,
self
.
response
.
read
(),
path
)
raise
ServerError
(
message
)
finally
:
socket
.
setdefaulttimeout
(
default_timeout
)
...
...
@@ -625,8 +641,9 @@ class ConnectionHelper:
elif
self
.
response
.
status
==
httplib
.
FORBIDDEN
:
raise
Unauthorized
(
"%s - %s"
%
(
path
,
parameter_dict
))
elif
self
.
response
.
status
!=
httplib
.
OK
:
message
=
'Server responded with wrong code %s with %s'
%
\
(
self
.
response
.
status
,
path
)
message
=
parsed_error_message
(
self
.
response
.
status
,
self
.
response
.
read
(),
path
)
raise
ServerError
(
message
)
finally
:
socket
.
setdefaulttimeout
(
default_timeout
)
...
...
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