Skip to content

Commit e63aeb2

Browse files
author
Kevin Hellemun
committed
Added method to retrieve response header from failed request. (#59)
1 parent 7568934 commit e63aeb2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

bunq/sdk/client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class ApiClient(object):
4646
HEADER_GEOLOCATION = 'X-Bunq-Geolocation'
4747
HEADER_SIGNATURE = 'X-Bunq-Client-Signature'
4848
HEADER_AUTHENTICATION = 'X-Bunq-Client-Authentication'
49+
HEADER_RESPONSE_ID_UPPER_CASED = 'X-Bunq-Client-Response-Id'
50+
HEADER_RESPONSE_ID_LOWER_CASED = 'x-bunq-client-response-id'
4951

5052
# Default header values
5153
_USER_AGENT_BUNQ = 'bunq-sdk-python/0.12.4'
@@ -222,7 +224,8 @@ def _assert_response_success(self, response):
222224
if response.status_code != self._STATUS_CODE_OK:
223225
raise ExceptionFactory.create_exception_for_response(
224226
response.status_code,
225-
self._fetch_error_messages(response)
227+
self._fetch_error_messages(response),
228+
self._fetch_response_id(response)
226229
)
227230

228231
@classmethod
@@ -266,6 +269,25 @@ def _fetch_error_descriptions(self, error_dict):
266269

267270
return error_descriptions
268271

272+
def _fetch_response_id(self, response):
273+
"""
274+
:type response: requests.Response
275+
276+
:rtype: str
277+
"""
278+
279+
headers = response.headers
280+
281+
if self.HEADER_RESPONSE_ID_UPPER_CASED in headers:
282+
return headers[self.HEADER_RESPONSE_ID_UPPER_CASED]
283+
284+
if self.HEADER_RESPONSE_ID_LOWER_CASED in headers:
285+
return headers[self.HEADER_RESPONSE_ID_LOWER_CASED]
286+
287+
return exception.BunqException(
288+
self._ERROR_COULD_NOT_DETERMINE_RESPONSE_ID_HEADER
289+
)
290+
269291
def put(self, uri_relative, request_bytes, custom_headers):
270292
"""
271293
:type uri_relative: str

0 commit comments

Comments
 (0)