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
When looking at the
IlluminateFoundationExceptionsHandler
class, you will find theHttpResponseException
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 theHttpResponseException
: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.