-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fix encryption when bad response exception #110
base: master
Are you sure you want to change the base?
Fix encryption when bad response exception #110
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.
Great catch @DrArmansky thanks for your contribution.
src/Hyperwallet/Util/ApiClient.php
Outdated
@@ -185,7 +185,8 @@ private function doRequest($method, $url, array $urlParams, array $options) { | |||
))); | |||
throw new HyperwalletApiException($errorResponse, $e); | |||
} catch (BadResponseException $e) { | |||
$body = \GuzzleHttp\json_decode($e->getResponse()->getBody(), true); | |||
$body = $this->isEncrypted ? \GuzzleHttp\json_decode(\GuzzleHttp\json_encode($this->encryption->decrypt($e->getResponse()->getBody())), true) : |
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.
-
Could you split each function call into single execution that will improve readability. or few free to introduce new function to handle the JSON decode.
-
Can you also introduce a Unit test to validate this use case as well.
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.
Ohh, I checked the whole method and I see that is the same approach on line 175
php-sdk/src/Hyperwallet/Util/ApiClient.php
Line 175 in a8cccc7
$body = $this->isEncrypted ? \GuzzleHttp\json_decode(\GuzzleHttp\json_encode($this->encryption->decrypt($response->getBody())), true) : |
- Could you introduce a function to handle the body decoding ? and reuse it on line 175 as well
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.
@grmeyer-hw-dev made the decryption of the response a separate function and unit test added. Please check.
000ff48
to
79a8f95
Compare
If encryption is used and BadResponseException was happened then when trying to extract the response body, an error occurs:
json_decode error: Syntax error
, which makes it impossible to see the real cause of the error. In this pull request, I'm fixing it.