Skip to content

Commit ed5092e

Browse files
author
Kevin Hellemun
committed
Changes based on review.
1 parent cd729b5 commit ed5092e

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed

bunq/sdk/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from bunq.sdk import context
88
from bunq.sdk import exception
9-
from bunq.sdk.exception_hanlder import ExceptionHandler
9+
from bunq.sdk.exception_factory import ExceptionFactory
1010
from bunq.sdk import security
1111
from bunq.sdk.json import converter
1212

@@ -202,7 +202,7 @@ def _assert_response_success(self, response):
202202
"""
203203

204204
if response.status_code != self._STATUS_CODE_OK:
205-
raise ExceptionHandler.create_exception_for_response(
205+
raise ExceptionFactory.create_exception_for_response(
206206
response.status_code,
207207
self._fetch_error_messages(response)
208208
)

bunq/sdk/exception.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class BunqError(Exception):
1+
class ApiException(Exception):
22
def __init__(self, message, response_code):
33
"""
44
:type message: str
@@ -8,7 +8,7 @@ def __init__(self, message, response_code):
88
self._response_code = response_code
99
self._message = message
1010

11-
super(BunqError, self).__init__(message)
11+
super(ApiException, self).__init__(message)
1212

1313
@property
1414
def message(self):
@@ -32,34 +32,33 @@ def __init__(self, message):
3232
super(BunqException, self).__init__(message)
3333

3434

35-
class ApiException(BunqError):
35+
class UnknownApiErrorException(ApiException):
3636
pass
3737

3838

39-
class BadRequestException(BunqError):
39+
class BadRequestException(ApiException):
4040
pass
4141

4242

43-
class UnauthorizedException(BunqError):
43+
class UnauthorizedException(ApiException):
4444
pass
4545

4646

47-
class ForbiddenException(BunqError):
47+
class ForbiddenException(ApiException):
4848
pass
4949

5050

51-
class NotFoundException(BunqError):
51+
class NotFoundException(ApiException):
5252
pass
5353

5454

55-
class MethodNotAllowedException(BunqError):
55+
class MethodNotAllowedException(ApiException):
5656
pass
5757

5858

59-
class ToManyRequestsException(BunqError):
59+
class ToManyRequestsException(ApiException):
6060
pass
6161

6262

63-
class PleaseContactBunqException(BunqError):
63+
class PleaseContactBunqException(ApiException):
6464
pass
65-

bunq/sdk/exception_hanlder.py renamed to bunq/sdk/exception_factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from bunq.sdk.exception import MethodNotAllowedException
66
from bunq.sdk.exception import ToManyRequestsException
77
from bunq.sdk.exception import PleaseContactBunqException
8+
from bunq.sdk.exception import UnknownApiErrorException
89
from bunq.sdk.exception import ApiException
9-
from bunq.sdk.exception import BunqError
1010

1111

12-
class ExceptionHandler(Exception):
12+
class ExceptionFactory:
1313
# Error response code constants
1414
_HTTP_RESPONSE_CODE_BAD_REQUEST = 400
1515
_HTTP_RESPONSE_CODE_UNAUTHORIZED = 401
@@ -30,7 +30,7 @@ def create_exception_for_response(cls, response_code, messages):
3030
:type messages: list[str]
3131
3232
:return: The exception according to the status code.
33-
:rtype: BunqError
33+
:rtype: ApiException
3434
"""
3535

3636
error_message = cls._generate_message_error(response_code, messages)
@@ -50,7 +50,7 @@ def create_exception_for_response(cls, response_code, messages):
5050
if response_code == cls._HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR:
5151
return PleaseContactBunqException(error_message, response_code)
5252

53-
return ApiException(error_message, response_code)
53+
return UnknownApiErrorException(error_message, response_code)
5454

5555
@classmethod
5656
def _generate_message_error(cls, response_code, messages):

tests/bunq_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from tests.config import Config
55
from bunq.sdk.context import ApiContext
66
from bunq.sdk.context import ApiEnvironmentType
7-
from bunq.sdk.model.generated import endpoint
8-
from bunq.sdk.exception import ApiException
97

108

119
class BunqSdkTestCase(unittest.TestCase):
@@ -35,10 +33,11 @@ def _get_api_context(cls):
3533

3634
try:
3735
api_context = ApiContext.restore(filename_bunq_config_full)
38-
endpoint.User.list(api_context)
39-
except (ApiException, FileNotFoundError):
36+
except FileNotFoundError:
4037
api_context = ApiContext(ApiEnvironmentType.SANDBOX, cls._API_KEY,
4138
cls._DEVICE_DESCRIPTION, [])
39+
else:
40+
api_context.ensure_session_active()
4241

4342
api_context.save(filename_bunq_config_full)
4443

0 commit comments

Comments
 (0)