Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bunq/sdk python#59 add response id to request error #64

Conversation

OGKevin
Copy link
Contributor

@OGKevin OGKevin commented Dec 26, 2017

Closes #59

  • Tested

@OGKevin OGKevin added this to the 0.12.5 milestone Dec 26, 2017
@OGKevin OGKevin self-assigned this Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@bunq bunq deleted a comment Dec 26, 2017
@OGKevin OGKevin force-pushed the feature/bunq/sdk_python#59-add_response_id_to_request_error branch from 284cc29 to a3ef206 Compare December 29, 2017 22:12
@bunq bunq deleted a comment Dec 29, 2017
@bunq bunq deleted a comment Dec 29, 2017
Copy link
Contributor Author

@OGKevin OGKevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No plurals allowed 🙅🏾‍♂️

@@ -215,7 +224,8 @@ def _assert_response_success(self, response):
if response.status_code != self._STATUS_CODE_OK:
raise ExceptionFactory.create_exception_for_response(
response.status_code,
self._fetch_error_messages(response)
self._fetch_error_messages(response),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plural

_GLUE_ERROR_MESSAGES = '\n'
_FORMAT_RESPONSE_ID_LINE = 'The response id to help bunq debug: {}'
_FORMAT_ERROR_MESSAGE_LINE = 'Error message: {}'
_GLUE_ERROR_MESSAGES_NEW_LINE = '\n'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plural

_FORMAT_RESPONSE_ID_LINE = 'The response id to help bunq debug: {}'
_FORMAT_ERROR_MESSAGE_LINE = 'Error message: {}'
_GLUE_ERROR_MESSAGES_NEW_LINE = '\n'
_GLUE_ERROR_MESSAGES_STRING_EMPTY = ''
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plural


return cls._glue_messages([line_response_code] + messages)
return cls._glue_messages(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plural

@OGKevin
Copy link
Contributor Author

OGKevin commented Jan 2, 2018

@epels all yours please 👀

epels
epels previously approved these changes Jan 2, 2018
Copy link

@epels epels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments

@@ -39,6 +46,8 @@ class ApiClient(object):
HEADER_GEOLOCATION = 'X-Bunq-Geolocation'
HEADER_SIGNATURE = 'X-Bunq-Client-Signature'
HEADER_AUTHENTICATION = 'X-Bunq-Client-Authentication'
HEADER_RESPONSE_ID_UPPER_CASED = 'X-Bunq-Client-Response-Id'
HEADER_RESPONSE_ID_LOWER_CASED = 'x-bunq-client-response-id'

# Default header values
_USER_AGENT_BUNQ = 'bunq-sdk-python/0.12.4'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget bumping version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens during release 🙃


@classmethod
def create_exception_for_response(cls, response_code, messages):
def create_exception_for_response(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg list not formatted according to PEP 8: https://www.python.org/dev/peps/pep-0008/#indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, this is how we do it. The pep8 one is weird and ugly.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 😝

response_code,
messages,
response_id
)

if response_code == cls._HTTP_RESPONSE_CODE_BAD_REQUEST:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating a mapping (response_code => exception type) for all these cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code has not been modified in this pr, please create a follow up issue for this.

If so, this must also be refactored in the other SDK's

"""
:type response_id: str
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ordered properly

"""
:type response_id: str
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ordered properly

@@ -63,15 +109,21 @@ def _generate_message_error(cls, response_code, messages):

line_response_code = cls._FORMAT_RESPONSE_CODE_LINE \
.format(response_code)
line_response_id = cls._FORMAT_RESPONSE_ID_LINE.format(response_id)
line_error_message = cls._FORMAT_ERROR_MESSAGE_LINE.format(
cls._GLUE_ERROR_MESSAGE_STRING_EMPTY.join(messages)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider whether _GLUE_ERROR_MESSAGE would be sufficient as a name here. Having the name imply it's an empty string is redundant information and not relevant for the consumer IMHO


return cls._glue_messages([line_response_code] + messages)
return cls._glue_all_error_message(
[line_response_code, line_response_id, line_error_message]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No trailing comma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only in multi line


class TestPagination(BunqSdkTestCase):
"""
Tests if the response id from a failed request can be retrieved
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring should start on the same line as the opening """

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also how we do it 😁 we ignore pep8 's suggestion to begin doctoring right behind """

"""
"""

caught_exception = None
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bunq bunq deleted a comment Jan 2, 2018
@bunq bunq deleted a comment Jan 2, 2018

self.assertIsNotNone(caught_exception)
self.assertIsNotNone(caught_exception.response_id)
self.assertIsNotNone(caught_exception.exception)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion seems redundant after using assertRaises?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

Copy link

@epels epels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andrederoos andrederoos merged commit cb3ead1 into develop Jan 2, 2018
@andrederoos andrederoos deleted the feature/bunq/sdk_python#59-add_response_id_to_request_error branch January 2, 2018 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants