-
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
Check if there is a hint exception defined #3
Check if there is a hint exception defined #3
Conversation
Observer/BeforeSending.php
Outdated
$messages = $this->json->unserialize($this->scopeConfig->getValue('sentry/event_filtering/messages')); | ||
foreach ($messages as $message) { | ||
if (str_contains($hintMessage, $message['message'])) { | ||
$observer->getEvent()->getSentryEvent()->unsEvent(); |
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.
Once we've unset the event there is no reason to keep looping, correct?
It may be a good idea to break out of the loop in that case 🙂
$observer->getEvent()->getSentryEvent()->unsEvent(); | |
$observer->getEvent()->getSentryEvent()->unsEvent(); | |
break; |
Observer/BeforeSending.php
Outdated
if ($hint?->exception !== null) { | ||
$hintMessage = $hint->exception->getMessage(); | ||
if ($hint->exception instanceof LocalizedException) { | ||
$hintMessage = $hint->exception->getRawMessage(); | ||
$event->setMessage($hintMessage); | ||
} |
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.
Aren't we able to get the message some other way when we do not have the exception, like getting it from the Event itself?
Then at least we will be able to continue to filter out events even without hint.
if ($hint?->exception !== null) { | |
$hintMessage = $hint->exception->getMessage(); | |
if ($hint->exception instanceof LocalizedException) { | |
$hintMessage = $hint->exception->getRawMessage(); | |
$event->setMessage($hintMessage); | |
} | |
$hintMessage = $hint?->exception?->getMessage() ?? $event->getMessage(); | |
if ($hint?->exception instanceof LocalizedException) { | |
$hintMessage = $hint->exception->getRawMessage() ; | |
$event->setMessage($hintMessage); | |
} |
Otherwise i would suggest flipping the logic of the if and returning early to reduct the depth of if/else
if ($hint?->exception !== null) { | |
$hintMessage = $hint->exception->getMessage(); | |
if ($hint->exception instanceof LocalizedException) { | |
$hintMessage = $hint->exception->getRawMessage(); | |
$event->setMessage($hintMessage); | |
} | |
if ($hint?->exception === null) { | |
return | |
} | |
$hintMessage = $hint->exception->getMessage(); | |
if ($hint->exception instanceof LocalizedException) { | |
$hintMessage = $hint->exception->getRawMessage(); | |
$event->setMessage($hintMessage); | |
} |
No description provided.