feat(exceptions): introduce NonReportableException to handle known errors and update Handler for selective reporting
This commit is contained in:
@@ -29,6 +29,7 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
protected $dontReport = [
|
||||
ProcessException::class,
|
||||
NonReportableException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -110,9 +111,14 @@ class Handler extends ExceptionHandler
|
||||
);
|
||||
}
|
||||
);
|
||||
// Check for errors that should not be reported to Sentry
|
||||
if (str($e->getMessage())->contains('No space left on device')) {
|
||||
// Log locally but don't send to Sentry
|
||||
logger()->warning('Disk space error: '.$e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Integration::captureUnhandledException($e);
|
||||
});
|
||||
}
|
||||
|
31
app/Exceptions/NonReportableException.php
Normal file
31
app/Exceptions/NonReportableException.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Exception that should not be reported to Sentry or other error tracking services.
|
||||
* Use this for known, expected errors that don't require external tracking.
|
||||
*/
|
||||
class NonReportableException extends Exception
|
||||
{
|
||||
/**
|
||||
* Create a new non-reportable exception instance.
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $code
|
||||
*/
|
||||
public function __construct($message = '', $code = 0, ?\Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create from another exception, preserving its message and stack trace.
|
||||
*/
|
||||
public static function fromException(\Throwable $exception): static
|
||||
{
|
||||
return new static($exception->getMessage(), $exception->getCode(), $exception);
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Notifications\Channels;
|
||||
|
||||
use App\Exceptions\NonReportableException;
|
||||
use App\Models\Team;
|
||||
use Exception;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -101,13 +102,11 @@ class EmailChannel
|
||||
$mailer->send($email);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
\Illuminate\Support\Facades\Log::error('EmailChannel failed: '.$e->getMessage(), [
|
||||
'notification' => get_class($notification),
|
||||
'notifiable' => get_class($notifiable),
|
||||
'team_id' => data_get($notifiable, 'id'),
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
// Check if this is a Resend domain verification error on cloud instances
|
||||
if (isCloud() && str_contains($e->getMessage(), 'domain is not verified')) {
|
||||
// Throw as NonReportableException so it won't go to Sentry
|
||||
throw NonReportableException::fromException($e);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user