utils/soap: use SOAPServiceUnreachable for all service down errors (#87028)
This commit is contained in:
parent
68764cd9c2
commit
8d6f202b16
|
@ -33,11 +33,11 @@ class SOAPError(APIError):
|
|||
|
||||
|
||||
class SOAPServiceUnreachable(SOAPError):
|
||||
def __init__(self, client, exception):
|
||||
def __init__(self, url, exception):
|
||||
super().__init__(
|
||||
f'SOAP service at {client.wsdl.location} is unreachable. Please contact its administrator: {exception}',
|
||||
f'SOAP service at {url} is unreachable. Please contact its administrator: {exception}',
|
||||
data={
|
||||
'wsdl': client.wsdl.location,
|
||||
'wsdl': url,
|
||||
'status_code': getattr(exception, 'status_code', None),
|
||||
'error': str(exception),
|
||||
},
|
||||
|
@ -76,9 +76,9 @@ class OperationProxyWrapper(OperationProxy):
|
|||
try:
|
||||
return super().__call__(*args, **kwargs)
|
||||
except RequestException as request_exception:
|
||||
raise SOAPServiceUnreachable(client, request_exception)
|
||||
raise SOAPServiceUnreachable(client.wsdl.location, request_exception)
|
||||
except TransportError as transport_error:
|
||||
raise SOAPServiceUnreachable(client, transport_error)
|
||||
raise SOAPServiceUnreachable(client.wsdl.location, transport_error)
|
||||
except Fault as fault:
|
||||
raise SOAPFault(client, fault)
|
||||
except ValidationError as validation_error:
|
||||
|
@ -174,9 +174,7 @@ class SOAPTransport(Transport):
|
|||
response = self.session.get(url, cache_duration=3600 * 12, cache_refresh=300)
|
||||
response.raise_for_status()
|
||||
except RequestException as e:
|
||||
raise SOAPError(
|
||||
'SOAP service is down, location %r cannot be loaded: %s' % (url, e), exception=e, url=url
|
||||
)
|
||||
raise SOAPServiceUnreachable(url, e)
|
||||
return response.content
|
||||
|
||||
def post_xml(self, *args, **kwargs):
|
||||
|
|
|
@ -456,7 +456,11 @@ def test_low_level_connection_error(
|
|||
):
|
||||
resp = app.get('/astregs/test/get-association-by-id', params={'association_id': '487464'})
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['data'] is None
|
||||
assert resp.json['data'] == {
|
||||
'error': 'mocked error',
|
||||
'status_code': None,
|
||||
'wsdl': 'https://test-ws-astre-gs.departement06.fr/axis2/services/Tiers?wsdl',
|
||||
}
|
||||
assert 'mocked error' in resp.json['err_desc']
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ from passerelle.base.models import Job, ResourceLog
|
|||
from passerelle.contrib.toulouse_maelis.models import Link, Referential, ToulouseMaelis
|
||||
from passerelle.contrib.toulouse_maelis.utils import get_public_criterias
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.soap import SOAPError
|
||||
from passerelle.utils.soap import SOAPError, SOAPServiceUnreachable
|
||||
from passerelle.utils.templates import render_to_string
|
||||
from tests.test_manager import login
|
||||
from tests.utils import FakedResponse, ResponsesSoap, generic_endpoint_url, setup_access_rights
|
||||
|
@ -362,14 +362,10 @@ def test_manager_update_referentials(admin_user, app, con):
|
|||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_call_with_wrong_wsdl_url(mocked_get, con):
|
||||
mocked_get.side_effect = CONNECTION_ERROR
|
||||
with pytest.raises(
|
||||
SOAPError,
|
||||
match='cannot be loaded: No address associated with hostname',
|
||||
) as e:
|
||||
with pytest.raises(SOAPServiceUnreachable, match='SOAP service at.*is unreachable') as e:
|
||||
con.call('Family', 'isWSRunning')
|
||||
assert e.value.err == 1
|
||||
assert e.value.http_status == 200
|
||||
assert e.value.url == 'https://example.org/FamilyService?wsdl'
|
||||
|
||||
|
||||
@mock.patch('passerelle.contrib.toulouse_maelis.models.ToulouseMaelis.soap_client_cache_timeout', 0)
|
||||
|
|
Loading…
Reference in New Issue