0003-api_particulier-improve-api-errors-38721.patch
passerelle/apps/api_particulier/models.py | ||
---|---|---|
87 | 87 |
(self.platform, response.status_code), |
88 | 88 |
log_error=True, |
89 | 89 |
data={ |
90 |
'code': 'connection-error', |
|
90 | 91 |
'platform': self.platform, |
91 | 92 |
'error': six.text_type(e), |
92 | 93 |
}) |
... | ... | |
99 | 100 |
(self.platform, response.status_code, content), |
100 | 101 |
log_error=True, |
101 | 102 |
data={ |
103 |
'code': 'non-json', |
|
102 | 104 |
'status_code': response.status_code, |
103 | 105 |
'exception': six.text_type(e), |
104 | 106 |
'platform': self.platform, |
... | ... | |
106 | 108 |
}) |
107 | 109 |
if response.status_code != 200: |
108 | 110 |
if data.get('error') == 'not_found': |
109 |
raise APIError(data.get('message', 'not-found')) |
|
111 |
raise APIError( |
|
112 |
'No data was found.', |
|
113 |
data={ |
|
114 |
'code': 'not-found', |
|
115 |
'platform': self.platform, |
|
116 |
'content': data, |
|
117 |
}) |
|
110 | 118 |
raise APIError( |
111 | 119 |
u'API-particulier platform "%s" returned a non 200 status %s: %s' % |
112 | 120 |
(self.platform, response.status_code, data), |
113 | 121 |
log_error=True, |
114 | 122 |
data={ |
123 |
'code': 'non-200', |
|
115 | 124 |
'status_code': response.status_code, |
116 | 125 |
'platform': self.platform, |
117 | 126 |
'content': data, |
tests/test_api_particulier.py | ||
---|---|---|
104 | 104 | |
105 | 105 |
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$') |
106 | 106 |
def api_particulier_error_500(url, request): |
107 |
return response(500, 'something bad happened', request=request)
|
|
107 |
return response(500, {'error': 500}, request=request)
|
|
108 | 108 | |
109 | 109 | |
110 | 110 |
@urlmatch(netloc=r'^particulier.*\.api\.gouv\.fr$') |
... | ... | |
149 | 149 |
assert resp.status_code == 200 |
150 | 150 |
assert resp.json['err'] == 1 |
151 | 151 |
assert resp.json['data']['status_code'] == 500 |
152 |
assert resp.json['data']['code'] == 'non-200' |
|
152 | 153 |
vector = [ |
153 | 154 |
(['impots_svair', 'avis-imposition'], { |
154 | 155 |
'numero_fiscal': 12, |
... | ... | |
173 | 174 |
assert resp.status_code == 200 |
174 | 175 |
assert resp.json['err'] == 1 |
175 | 176 |
assert 'returned non-JSON content' in resp.json['err_desc'] |
177 |
assert resp.json['data']['code'] == 'non-json' |
|
176 | 178 |
vector = [ |
177 | 179 |
(['impots_svair', 'avis-imposition'], { |
178 | 180 |
'numero_fiscal': 12, |
... | ... | |
196 | 198 |
params=params) |
197 | 199 |
assert resp.status_code == 200 |
198 | 200 |
assert resp.json['err'] == 1 |
199 |
assert resp.json['err_desc'].endswith(u'à un avis') |
|
201 |
assert resp.json['err_desc'] == 'No data was found.' |
|
202 |
assert resp.json['data']['code'] == 'not-found' |
|
200 | 203 |
vector = [ |
201 | 204 |
(['impots_svair', 'avis-imposition'], { |
202 | 205 |
'numero_fiscal': 12, |
203 |
- |