skip to Main Content

Exceptions that were throw new exception with HttpResponseException do not arrive to Sentry.
I have a controller with the following code:

public function search($request): mixed
{
    try {
        $response = $this->myService->search($request);
        return is_array($response) ? new MyResource(["response" => $response]) : $response;
    } catch (Exception $ex) {
        throw new HttpResponseException(response()->json($e->getMessage(), 500));

    }
}

If i change the catch scope to throw error like this way below, its sent successfully to Sentry. It works if $ex is of Exception instance too.


    } catch (Throwable $ex) {
        throw $ex;
    }

My Sentry Config in config/sentry.php is with default configuration.

2

Answers


  1. When looking at the IlluminateFoundationExceptionsHandler class, you will find the HttpResponseException in the $internalDontReport array.

    That is the reason why this exception is not sent to Sentry.

    You can override the array in AppExceptionsHandler, and remove the HttpResponseException:

    protected $internalDontReport = [
        AuthenticationException::class,
        AuthorizationException::class,
        BackedEnumCaseNotFoundException::class,
        HttpException::class,
        ModelNotFoundException::class,
        MultipleRecordsFoundException::class,
        RecordsNotFoundException::class,
        SuspiciousOperationException::class,
        TokenMismatchException::class,
        ValidationException::class,
    ];
    
    Login or Signup to reply.
  2. I’m facing the same problem, errors don’t reach Sentry sandbox.

    Remove HttpException from $internalDontReport array does not work for me, any other shot ?

    I found this issue https://github.com/getsentry/sentry-laravel/issues/383, maybe sentry could only access unhandled exceptions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search