From 78069297203e711ff585d2d821ddd71bfb997c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Pel=C3=AD=C5=A1ek?= Date: Mon, 13 Nov 2023 11:04:38 +0100 Subject: [PATCH] Added ErrorHandlingMode outputable --- src/ErrorHandlingMode.php | 2 ++ src/Graphpinator.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/ErrorHandlingMode.php b/src/ErrorHandlingMode.php index de7ccb927..36c8c14af 100644 --- a/src/ErrorHandlingMode.php +++ b/src/ErrorHandlingMode.php @@ -8,6 +8,8 @@ enum ErrorHandlingMode { // Catch all exceptions. ClientAware exceptions returns corresponding result, unknown exceptions throw an "Unknown error". case ALL; + // Catch outputable ClientAware exceptions and return corresponding result, internal exceptions are rethrown. + case OUTPUTABLE; // Catch ClientAware exceptions and return corresponding result, unknown exceptions are rethrown. case CLIENT_AWARE; // Rethrow all exceptions. diff --git a/src/Graphpinator.php b/src/Graphpinator.php index 5b7065bd3..de263f62f 100644 --- a/src/Graphpinator.php +++ b/src/Graphpinator.php @@ -92,6 +92,7 @@ public function run(\Graphpinator\Request\RequestFactory $requestFactory) : \Gra return match($this->errorHandlingMode) { ErrorHandlingMode::ALL => $this->handleAll($exception), + ErrorHandlingMode::OUTPUTABLE => $this->handleOutputable($exception), ErrorHandlingMode::CLIENT_AWARE => $this->handleClientAware($exception), ErrorHandlingMode::NONE => $this->handleNone($exception), }; @@ -128,6 +129,13 @@ private function handleAll(\Throwable $exception) : Result ]); } + private function handleOutputable(\Throwable $exception) : Result + { + return $exception instanceof \Graphpinator\Exception\ClientAware && $exception->isOutputable() + ? new \Graphpinator\Result(null, [self::serializeError($exception)]) + : throw $exception; + } + private function handleClientAware(\Throwable $exception) : Result { return $exception instanceof \Graphpinator\Exception\ClientAware