From d5085329c356a0f118e0be95430cb15cbbf92dbd Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 16 Jun 2020 10:53:26 +0200 Subject: [PATCH] api_particulier: do not log 404 for family endpoint (#44043) --- passerelle/apps/api_particulier/models.py | 4 +++- tests/test_api_particulier.py | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/passerelle/apps/api_particulier/models.py b/passerelle/apps/api_particulier/models.py index 9e938ea5..70de9b13 100644 --- a/passerelle/apps/api_particulier/models.py +++ b/passerelle/apps/api_particulier/models.py @@ -108,7 +108,9 @@ class APIParticulier(BaseResource): }) if response.status_code != 200: # avoid logging 404 errors indicating no matching data was found - if data.get('error') == 'not_found' and 'incorrects ou ne correspondent' in data['message']: + if data.get('error') == 'not_found' and \ + ('incorrects ou ne correspondent' in data['message'] or + 'Dossier allocataire inexistant' in data['message']): raise APIError( 'No matching tax notice was found.', data={ diff --git a/tests/test_api_particulier.py b/tests/test_api_particulier.py index d2dc7546..c043f4dc 100644 --- a/tests/test_api_particulier.py +++ b/tests/test_api_particulier.py @@ -127,6 +127,14 @@ def api_particulier_error_not_found(url, request): }, request=request) +@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$') +def api_particulier_error_not_found_caf(url, request): + return response(404, { + 'error': 'not_found', + 'message': 'Dossier allocataire inexistant. Le document ne peut être édité.' + }, request=request) + + @pytest.yield_fixture def mock_api_particulier(): with HTTMock(api_particulier_v2_avis_imposition, api_particulier_v2_situation_familiale): @@ -257,7 +265,7 @@ def test_detail_page(app, resource): @pytest.mark.parametrize( 'mock,should_log', [ (api_particulier_error_not_found, False), (api_particulier_error_500, True), - (api_particulier_error_not_json, True) + (api_particulier_error_not_json, True), (api_particulier_error_not_found_caf, False) ] ) def test_api_particulier_dont_log_not_found(app, resource, mock, should_log): -- 2.20.1