signal_arretes: fix RequestException not raised by raise_for_status (#79958)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
06f22a03f8
commit
4f136ee898
|
@ -107,6 +107,7 @@ class SignalArretes(BaseResource, HTTPResource):
|
|||
url = f'{self.base_url}/CreationDemandeService.svc/{endpoint}'
|
||||
|
||||
try:
|
||||
response = None
|
||||
if not post_data:
|
||||
response = self.requests.get(url)
|
||||
else:
|
||||
|
@ -114,7 +115,7 @@ class SignalArretes(BaseResource, HTTPResource):
|
|||
|
||||
response.raise_for_status()
|
||||
except RequestException as e:
|
||||
if response.status_code == 400:
|
||||
if response is not None and response.status_code == 400:
|
||||
error_msg_match = re.search(
|
||||
'Le message d\'exception est \'(.*)\'\\. Pour plus d\'informations', response.text
|
||||
)
|
||||
|
|
|
@ -20,6 +20,7 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
from httmock import HTTMock, response, urlmatch
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from passerelle.apps.signal_arretes.models import SignalArretes
|
||||
from tests.utils import generic_endpoint_url, setup_access_rights
|
||||
|
@ -315,3 +316,14 @@ def test_error_handling(mocked_get, app, connector, status_code, body, expected_
|
|||
assert 'err' in result.json
|
||||
assert result.json['err']
|
||||
assert expected_message in result.json['err_desc']
|
||||
|
||||
|
||||
@patch('passerelle.utils.Request.get')
|
||||
def test_more_error_handling(mocked_get, app, connector):
|
||||
endpoint = generic_endpoint_url('signal-arretes', 'cities', slug=connector.slug)
|
||||
mocked_get.side_effect = ConnectionError
|
||||
result = app.get(endpoint)
|
||||
|
||||
assert 'err' in result.json
|
||||
assert result.json['err']
|
||||
assert 'An error occured during the request to Signal Arrêtés' in result.json['err_desc']
|
||||
|
|
Loading…
Reference in New Issue