Skip to content

Commit 78b3a82

Browse files
committed
feature/python-sdk-refactor Updated Type Annotations for all the Exception classes.
1 parent 7279a09 commit 78b3a82

File tree

4 files changed

+53
-55
lines changed

4 files changed

+53
-55
lines changed

bunq/sdk/exception/EXCEPTIONS.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Exceptions
2-
When you make a request via the SDK, there is a chance of request failing
2+
When you make a request via the SDK, there is a cobjecthance of request objectfailiobjectng
33
due to various reasons. When such a failure happens, an exception
44
corresponding to the error occurred is raised.
55

@@ -25,23 +25,23 @@ page here: https://doc.bunq.com/api/1/page/errors
2525
All the exceptions have the same base exception which looks like this:
2626
```python
2727
class ApiException(Exception):
28-
def __init__(self, message, response_code):
29-
pass
30-
31-
@property
32-
def message(self):
28+
def __init__(self,
29+
message: str,
30+
response_code: int) -> None:
3331
"""
34-
:rtype: str
32+
33+
:param message:
34+
:param response_code:
3535
"""
3636

37-
return self._message
37+
pass
3838

3939
@property
40-
def response_code(self):
41-
"""
42-
:rtype: int
43-
"""
40+
def message(self) -> str:
41+
return self._message
4442

43+
@property
44+
def response_code(self) -> int:
4545
return self._response_code
4646
```
4747
This means that each exception will have the response code and the error message

bunq/sdk/exception/api_exception.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
class ApiException(Exception):
2-
def __init__(self, message, response_code, response_id):
2+
def __init__(self,
3+
message: str,
4+
response_code: int,
5+
response_id: str) -> None:
36
"""
4-
:type response_id: str
5-
:type message: str
6-
:type response_code: int
7+
8+
:param message:
9+
:param response_code:
10+
:param response_id:
711
"""
812

913
self._response_id = response_id
@@ -13,25 +17,13 @@ def __init__(self, message, response_code, response_id):
1317
super(ApiException, self).__init__(message)
1418

1519
@property
16-
def message(self):
17-
"""
18-
:rtype: str
19-
"""
20-
20+
def message(self) -> str:
2121
return self._message
2222

2323
@property
24-
def response_code(self):
25-
"""
26-
:rtype: int
27-
"""
28-
24+
def response_code(self) -> int:
2925
return self._response_code
3026

3127
@property
32-
def response_id(self):
33-
"""
34-
:rtype: str
35-
"""
36-
28+
def response_id(self) -> str:
3729
return self._response_id

bunq/sdk/exception/bunq_exception.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
class BunqException(Exception):
2-
def __init__(self, message):
2+
def __init__(self, message: str) -> None:
3+
"""
4+
5+
:param message:
6+
"""
7+
38
super(BunqException, self).__init__(message)

bunq/sdk/exception/exception_factory.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import List
2+
3+
from bunq.sdk.exception.api_exception import ApiException
14
from bunq.sdk.exception.bad_request_exception import BadRequestException
25
from bunq.sdk.exception.forbidden_exception import ForbiddenException
36
from bunq.sdk.exception.method_not_allowed_exception import MethodNotAllowedException
@@ -28,17 +31,16 @@ class ExceptionFactory:
2831
@classmethod
2932
def create_exception_for_response(
3033
cls,
31-
response_code,
32-
messages,
33-
response_id
34-
):
34+
response_code: int,
35+
messages: List[str],
36+
response_id: str
37+
) -> ApiException:
3538
"""
36-
:type response_code: int
37-
:type messages: list[str]
38-
:type response_id: str
3939
40+
:param response_code:
41+
:param messages:
42+
:param response_id:
4043
:return: The exception according to the status code.
41-
:rtype: ApiException
4244
"""
4345

4446
error_message = cls._generate_message_error(
@@ -97,31 +99,30 @@ def create_exception_for_response(
9799
)
98100

99101
@classmethod
100-
def _generate_message_error(cls, response_code, messages, response_id):
102+
def _generate_message_error(cls,
103+
response_code: int,
104+
messages: List[str],
105+
response_id: str) -> str:
101106
"""
102-
:type response_code: int
103-
:type messages: list[str]
104-
:type response_id: str
105107
106-
:rtype: str
108+
:param response_code:
109+
:param messages:
110+
:param response_id:
107111
"""
108112

109-
line_response_code = cls._FORMAT_RESPONSE_CODE_LINE \
110-
.format(response_code)
113+
line_response_code = cls._FORMAT_RESPONSE_CODE_LINE.format(response_code)
111114
line_response_id = cls._FORMAT_RESPONSE_ID_LINE.format(response_id)
112-
line_error_message = cls._FORMAT_ERROR_MESSAGE_LINE.format(
113-
cls._GLUE_ERROR_MESSAGE_STRING_EMPTY.join(messages)
114-
)
115+
line_error_message = cls._FORMAT_ERROR_MESSAGE_LINE.format(cls._GLUE_ERROR_MESSAGE_STRING_EMPTY.join(messages))
115116

116-
return cls._glue_all_error_message(
117-
[line_response_code, line_response_id, line_error_message]
118-
)
117+
return cls._glue_all_error_message([line_response_code, line_response_id, line_error_message])
119118

120119
@classmethod
121-
def _glue_all_error_message(cls, messages):
120+
def _glue_all_error_message(cls, messages: List[str]) -> str:
122121
"""
123-
:type messages: list[str]
124122
123+
:param messages:
124+
:type messages: List[str]
125+
:return:
125126
:rtype: str
126127
"""
127128

0 commit comments

Comments
 (0)