-
Notifications
You must be signed in to change notification settings - Fork 784
[DEVX-5241] Add last_request and last_response to client. #382
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test or two to assert that this works?
twilio/http/http_client.py
Outdated
@@ -47,4 +47,7 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None, | |||
timeout=timeout, | |||
) | |||
|
|||
self.last_request = request | |||
self.last_response = response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's set these to None
in the constructor so developers can always be sure that the attributes exist.
twilio/http/http_client.py
Outdated
@@ -47,4 +50,7 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None, | |||
timeout=timeout, | |||
) | |||
|
|||
self.last_request = request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we set this before we send the request? That way if session.send
raises an exception it will still be set.
twilio/http/http_client.py
Outdated
@@ -40,11 +43,15 @@ def request(self, method, url, params=None, data=None, headers=None, auth=None, | |||
|
|||
request = Request(method.upper(), url, params=params, data=data, headers=headers, auth=auth) | |||
|
|||
self.last_request = request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these be twilio.Request
not requests.models.Request
? Same with the response object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes thats what the other libraries do.
…oper contructions and setting none on request exception
…41_add_last_request-response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there, I'm curious about the rationale for adding this feature (something that ideally the PR description would explain). What are example scenarios in which you'd use TwilioHttpClient.last_request
/last_response
? Alos, should it be documented explicitly that using it is not safe in a threaded environment (see also #580)?
self.assertIsNotNone(self.client.last_request) | ||
self.assertIsNone(self.client.last_response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the self.client.request(...)
call above raises an exception as expected, then these assertions will never run.
No description provided.