api_particulier: improve api errors (#38721)
This commit is contained in:
parent
ec83c19aa4
commit
91b1c80fbc
|
@ -87,6 +87,7 @@ class APIParticulier(BaseResource):
|
|||
(self.platform, response.status_code),
|
||||
log_error=True,
|
||||
data={
|
||||
'code': 'connection-error',
|
||||
'platform': self.platform,
|
||||
'error': six.text_type(e),
|
||||
})
|
||||
|
@ -99,6 +100,7 @@ class APIParticulier(BaseResource):
|
|||
(self.platform, response.status_code, content),
|
||||
log_error=True,
|
||||
data={
|
||||
'code': 'non-json',
|
||||
'status_code': response.status_code,
|
||||
'exception': six.text_type(e),
|
||||
'platform': self.platform,
|
||||
|
@ -107,12 +109,19 @@ 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']:
|
||||
raise APIError(data.get('message', 'not-found'))
|
||||
raise APIError(
|
||||
'No matching tax notice was found.',
|
||||
data={
|
||||
'code': 'not-found',
|
||||
'platform': self.platform,
|
||||
'content': data,
|
||||
})
|
||||
raise APIError(
|
||||
u'API-particulier platform "%s" returned a non 200 status %s: %s' %
|
||||
(self.platform, response.status_code, data),
|
||||
log_error=True,
|
||||
data={
|
||||
'code': 'non-200',
|
||||
'status_code': response.status_code,
|
||||
'platform': self.platform,
|
||||
'content': data,
|
||||
|
|
|
@ -104,7 +104,7 @@ def api_particulier_v2_situation_familiale(url, request):
|
|||
|
||||
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$')
|
||||
def api_particulier_error_500(url, request):
|
||||
return response(500, 'something bad happened', request=request)
|
||||
return response(500, {'error': 500}, request=request)
|
||||
|
||||
|
||||
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$')
|
||||
|
@ -149,6 +149,7 @@ def test_error(app, resource, mock_api_particulier):
|
|||
assert resp.status_code == 200
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['data']['status_code'] == 500
|
||||
assert resp.json['data']['code'] == 'non-200'
|
||||
vector = [
|
||||
(['impots_svair', 'avis-imposition'], {
|
||||
'numero_fiscal': 12,
|
||||
|
@ -173,6 +174,7 @@ def test_error(app, resource, mock_api_particulier):
|
|||
assert resp.status_code == 200
|
||||
assert resp.json['err'] == 1
|
||||
assert 'returned non-JSON content' in resp.json['err_desc']
|
||||
assert resp.json['data']['code'] == 'non-json'
|
||||
vector = [
|
||||
(['impots_svair', 'avis-imposition'], {
|
||||
'numero_fiscal': 12,
|
||||
|
@ -196,7 +198,8 @@ def test_error(app, resource, mock_api_particulier):
|
|||
params=params)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'].endswith(u'à un avis')
|
||||
assert resp.json['err_desc'] == 'No matching tax notice was found.'
|
||||
assert resp.json['data']['code'] == 'not-found'
|
||||
vector = [
|
||||
(['impots_svair', 'avis-imposition'], {
|
||||
'numero_fiscal': 12,
|
||||
|
|
Loading…
Reference in New Issue