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

Fix encryption when bad response exception #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

DrArmansky
Copy link

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.

Copy link
Collaborator

@grmeyer-hw-dev grmeyer-hw-dev left a 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.

@@ -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) :
Copy link
Collaborator

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.

Copy link
Collaborator

@grmeyer-hw-dev grmeyer-hw-dev Aug 19, 2022

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

$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

Copy link
Author

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.

@DrArmansky DrArmansky force-pushed the fix/bad-response-exception-encryption branch from 000ff48 to 79a8f95 Compare January 26, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants