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

Does captureUnhandleException still work for Laravel 11 #871

Closed
sts-ryan-holton opened this issue Mar 26, 2024 · 1 comment
Closed

Does captureUnhandleException still work for Laravel 11 #871

sts-ryan-holton opened this issue Mar 26, 2024 · 1 comment

Comments

@sts-ryan-holton
Copy link

Problem Statement

Hi,

I've recently updated to Laravel 11. I notice that your guide for Laravel 11 utilises Integration::handles() and not Integration::captureUnhandledException().

Am I still able to use this or must I use handles. If so, I need to exclude certain exceptions as per my code, should I utilise $e or $exceptions.

Solution Brainstorm

My code

->withExceptions(function (Exceptions $exceptions) {
        $exceptions->reportable(function (Throwable $e) {
            if ($e !== null && is_string($e->getMessage())) {
                if (Str::contains($e->getMessage(), ['has been attempted too many times', 'Deadlock found when trying to get lock'])) {
                    return false;
                }
            }

            Integration::captureUnhandledException($e);
        });
});
@stayallive
Copy link
Collaborator

stayallive commented Mar 26, 2024

I'll let you in on a little "secret" 😉

/**
* Convienence method to register the exception handler with Laravel 11.0 and up.
*/
public static function handles(Exceptions $exceptions): void
{
$exceptions->reportable(static function (Throwable $exception) {
self::captureUnhandledException($exception);
});
}

You are totally fine to keep using Integration::captureUnhandledException (we do it too), if you upgrade from Laravel 10 there is nothing for you to change if you don't want to. The guide for Laravel 11 is for new installations or people using the new L11 structure. Our L10 docs are also available if you need them: https://docs.sentry.io/platforms/php/guides/laravel/other-versions/laravel8-10/.

I do want to mention that the before_send callback is our preferred method of filtering what you do or do not want to send to Sentry: https://docs.sentry.io/platforms/php/guides/laravel/configuration/filtering/#filtering-error-events.

Edit: Sorry if I closed this a bit quick, feel free to re-open if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants