-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: better exception handling #40
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Troubleshooting issues with SmarterU is made several times more complicated than it needs to be because we don't capture useful information in the exception and log it anywhere. I am to fix this by adding request and response to the exception details. I don't want sensitive credentials going in our logs so I made sure to sanitize the request.
brianreichtcs
requested review from
a team and
tomegantcs
and removed request for
a team
November 15, 2023 20:29
Closing this until I'm done making changes |
tomegantcs
reviewed
Nov 16, 2023
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.
I don't think it would be difficult to add tests to see that something was sent to a logger. In tests/Client/AddUsersToGroupClientTest.php
for instance line 287 would be changed to:
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
$logger->expects($this->once())->method('error')->with(
$this->identicalTo('Failed to make request to SmarterU API. See context for request/response details.'),
$this->identicalTo([
'request' => // I'm not sure but maybe you put 'cat' here and see what the failure looks like to get the text?
'response' => $body
])
);
$client
->setLogger($logger)
->setHttpClient($httpClient);
tomegantcs
approved these changes
Nov 16, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If approved this PR:
psr/log
logFailedRequest
toClient
which, if a logger is present, logs the failed request/response.logFailedRequest()
everywhere aSmarterUException
is thrown.With this change in place, we can actually capture information we need to troubleshoot integration issues.
One thing you might wonder about is, why am I not testing that the logger gets data when a failure occurs? The reason is because
psr/log
doesn't ship a test logger, onlyNullLogger
, which is a "no-op" implementation that I cannot expect to validate log events.