Skip to content

Commit

Permalink
Added ErrorHandlingMode outputable
Browse files Browse the repository at this point in the history
  • Loading branch information
Václav Pelíšek committed Nov 13, 2023
1 parent 1e5530e commit 7806929
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ErrorHandlingMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions src/Graphpinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7806929

Please sign in to comment.