diff --git a/src/sentry/src/Annotation/Graceful.php b/src/sentry/src/Annotation/Graceful.php new file mode 100644 index 000000000..9c078c3e0 --- /dev/null +++ b/src/sentry/src/Annotation/Graceful.php @@ -0,0 +1,50 @@ +getAnnotationMetadata(); + + /** @var null|Graceful $annotation */ + $annotation = $metadata->method[Graceful::class] ?? null; + + if ($annotation === null) { + return $proceedingJoinPoint->process(); + } + + try { + return $proceedingJoinPoint->process(); + } catch (Throwable $e) { + return match ($annotation->strategy) { + Graceful::STRATEGY_FALLBACK => value($annotation->fallback, $proceedingJoinPoint, $e), + Graceful::STRATEGY_SWALLOW => null, + Graceful::STRATEGY_RETHROW => throw $e, + Graceful::STRATEGY_TRANSLATE => throw new ($annotation->mapTo ?? Throwable::class)('Translated Exception', 0, $e), + default => null, + }; + } finally { + if (isset($e) && $annotation->report) { + SentrySdk::getCurrentHub()->captureException($e); + } + } + } +} diff --git a/src/sentry/src/ConfigProvider.php b/src/sentry/src/ConfigProvider.php index 31a99d4fd..ec1a23caf 100644 --- a/src/sentry/src/ConfigProvider.php +++ b/src/sentry/src/ConfigProvider.php @@ -23,6 +23,7 @@ public function __invoke(): array Aspect\CacheAspect::class, Aspect\CoroutineAspect::class, Aspect\FilesystemAspect::class, + Aspect\GracefulAspect::class, Aspect\GuzzleHttpClientAspect::class, Aspect\LoggerAspect::class, Aspect\RedisAspect::class,