The best place to look is here: https://github.com/stayallive/wp-sentry#capturing-handled-exceptions.
However this assumes you have an exception which you don’t, you have a WP_Error object. So you could do something like this instead:
if (is_wp_error($result)) {
if (function_exists('wp_sentry_safe')) {
wp_sentry_safe(function (\Sentry\State\HubInterface $client) use ($result) {
$client->withScope(function (\Sentry\State\Scope $scope) use ($client, $result) {
$scope->setExtra('messages', $result-> get_error_messages());
$client->captureMessage('CHANGEME: Error while doing...');
});
});
}
}
Let me know if that helps!
Hi Alex,
thanks for reply.
Your snippet works! Thanks a lot, meanwhile i was trying with this
try {
myMethodThatCanThrowAnException();
} catch ( \Exception $e ) {
// We are using wp_sentry_safe to make sure this code runs even if the Sentry plugin is disabled
if ( function_exists( 'wp_sentry_safe' ) ) {
wp_sentry_safe( function ( \Sentry\State\HubInterface $client ) use ( $e ) {
$client->captureException( $e );
} );
}
wp_die( 'There was an error doing this thing you were doing, we have been notified!' );
}
and it works as well!
Thank you
That snippet you shared also works but a WP_Error is not an exception so you need a little different method to capture those.
Glad to hear it works, thanks for the update!