troccoli's avatar

Exception logging

In our app we do not, yet, allow users to sign-up using Google SSO. But we do allow them to sign-in. So when a user tries to sign-in for the first time I throw an UnregisteredGoogleUser exception.

The idea is that the user will be presented with a page were we explain the situation and what to do next. And that is the end of it. I don't want the exception to be reported, not even in the logs.

I though by returning false from the render() method would mean exactly that: no reporting. But the exception is still logged as an error

[2025-09-24 10:52:24] production.ERROR: {"exception":"[object] (App\\Exceptions\\UnregisteredGoogleUser(code: 0): at /var/www/html/app/Services/AuthenticationService.php:119)

The app runs on AWS and I am using stderr as the logging channel.

What am I doing wrong? How can I prevent an exception that my app handles to be logged?

0 likes
3 replies
LaryAI's avatar
Level 58

You’re very close—the confusion is understandable! Here’s the problem and how to fix it:

Why Is Your Exception Still Logged?

Returning false from a custom exception’s report() method prevents Laravel from sending your exception to the handler's report() method—this skips logging via Laravel's error channels (database, Bugsnag, etc.).
However, uncaught exceptions (even if rendered nicely for the user) can still bubble up and be caught by PHP’s error handler, which may log them by default if not handled as Laravel expects.

Solution

You should let your exception extend Laravel's base Exception instead of RuntimeException. Laravel looks for the report() method on exceptions that extend its own Exception class. If you extend RuntimeException, your report() method isn't invoked automatically.

So, update your exception like this:

Key Points

  • Must extend Exception, not RuntimeException for Laravel to respect report().
  • Your report() is implemented correctly (false disables logging).
  • Your render() method is fine.

Final Tip

  • If you must throw exceptions outside of controllers, ensure they’re still handled within Laravel’s lifecycle. For edge cases (like jobs/CLI), you may also want to manually catch and suppress/log them as you wish.

Summary:
Change from RuntimeException to Exception, keep your report() method, and Laravel will not log your custom exception.

troccoli's avatar
troccoli
OP
Best Answer
Level 6

My solution was to have the exception implements Illuminate\Contracts\Debug\ShouldntReport as also specified in the docs

Please or to participate in this conversation.