Skip to content
Snippets Groups Projects
Commit c7e4fa23 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

Merge branch 'f-fix-timeout-error-messages' into 'dev'

F fix timeout error messages

See merge request !169
parents 2f7cb996 84443119
No related branches found
No related tags found
2 merge requests!175BUG: Request responses without the "Set-Cookie" header no longer overwrite the...,!169F fix timeout error messages
Pipeline #59663 passed
......@@ -27,7 +27,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`authentication/interface/on_response()` does not overwrite
`auth_token` if new value is `None`
* [#119](https://gitlab.com/linkahead/linkahead-pylib/-/issues/119)
The diff returned by compare_entities now uses id instead of name as key if either property does not have a name
The diff returned by compare_entities now uses id instead of name as
key if either property does not have a name
* [#87](https://gitlab.com/linkahead/linkahead-pylib/-/issues/87)
`XMLSyntaxError` messages when parsing (incomplete) responses in
case of certain connection timeouts.
### Security ###
......
......@@ -94,12 +94,26 @@ class HTTPServerError(LinkAheadException):
"""HTTPServerError represents 5xx HTTP server errors."""
def __init__(self, body):
xml = etree.fromstring(body)
error = xml.xpath('/Response/Error')[0]
msg = error.get("description")
if error.text is not None:
msg = msg + "\n\n" + error.text
try:
# This only works if the server sends a valid XML
# response. Then it can be parsed for more information.
xml = etree.fromstring(body)
if xml.xpath('/Response/Error'):
error = xml.xpath('/Response/Error')[0]
msg = error.get("description") if error.get("description") is not None else ""
if error.text is not None:
if msg:
msg = msg + "\n\n" + error.text
else:
msg = error.text
else:
# Valid XML, but no error information
msg = body
except etree.XMLSyntaxError:
# Handling of incomplete responses, e.g., due to timeouts,
# c.f. https://gitlab.com/linkahead/linkahead-pylib/-/issues/87.
msg = body
LinkAheadException.__init__(self, msg)
......
......@@ -30,7 +30,7 @@ import linkahead as db
from linkahead.common.models import raise_errors
from linkahead.exceptions import (AuthorizationError,
EntityDoesNotExistError, EntityError,
EntityHasNoDatatypeError,
EntityHasNoDatatypeError, HTTPServerError,
TransactionError, UniqueNamesError,
UnqualifiedParentsError,
UnqualifiedPropertiesError)
......@@ -315,3 +315,26 @@ def test_container_with_faulty_elements():
# record raises both of them
assert (isinstance(err, UnqualifiedParentsError) or
isinstance(err, UnqualifiedPropertiesError))
def test_incomplete_server_error_response():
"""The reason behind https://gitlab.com/linkahead/linkahead-pylib/-/issues/87."""
# Case 1: Response is no XML at all
err = HTTPServerError("Bla")
assert str(err) == "Bla"
# Case 2: Response is an incomplete XML, e.g. due to very unlucky timeout
err = HTTPServerError("<incomplete>XML</inc")
assert str(err) == "<incomplete>XML</inc"
# Case 3: Response is complete XML but doesn't have response and or error information
err = HTTPServerError("<complete>XML</complete>")
assert str(err) == "<complete>XML</complete>"
# Case 4: Response is an XML response but the error is lacking a description
err = HTTPServerError("<Response><Error>complete error</Error></Response>")
assert str(err) == "complete error"
# Case 5: Healthy error Response
err = HTTPServerError("<Response><Error description='Error'>complete error</Error></Response>")
assert str(err) == "Error\n\ncomplete error"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment