Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Fix error handling of \Throwable
Browse files Browse the repository at this point in the history
  • Loading branch information
crisu83 committed Oct 8, 2018
1 parent da1c0d5 commit 50003e9
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Execution/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Digia\GraphQL\Type\Definition\SerializableTypeInterface;
use Digia\GraphQL\Type\Definition\TypeInterface;
use Digia\GraphQL\Type\Definition\UnionType;
use InvalidArgumentException;
use React\Promise\ExtendedPromiseInterface;
use React\Promise\FulfilledPromise;
use React\Promise\PromiseInterface;
Expand Down Expand Up @@ -114,8 +113,8 @@ public function execute(): ?array
$result = $operation->getOperation() === 'mutation'
? $this->executeFieldsSerially($objectType, $rootValue, $path, $fields)
: $this->executeFields($objectType, $rootValue, $path, $fields);
} catch (ExecutionException $ex) {
$this->handleError($ex);
} catch (\Throwable $ex) {
$this->handleError(new ExecutionException($ex->getMessage(), null, null, null, null, null, $ex));
return null;
}

Expand Down Expand Up @@ -171,7 +170,6 @@ public function getOperationType(Schema $schema, OperationDefinitionNode $operat
* @param array $fields
*
* @return array
* @throws InvalidArgumentException
*/
public function executeFieldsSerially(
ObjectType $objectType,
Expand Down Expand Up @@ -255,6 +253,7 @@ public function getFieldDefinition(
return $typeNameMetaFieldDefinition;
}

/** @noinspection PhpUnhandledExceptionInspection */
$fields = $parentType->getFields();

return $fields[$fieldName] ?? null;
Expand Down Expand Up @@ -296,16 +295,14 @@ public function completeValueCatchingError(
$result
);

if ($this->isPromise($completed)) {
$context = $this->context;

/** @var ExtendedPromiseInterface $completed */
return $completed->then(null, function ($error) use ($context, $fieldNodes, $path) {
//@TODO Handle $error better
if ($completed instanceof ExtendedPromiseInterface) {
return $completed->then(null, function ($error) use ($fieldNodes, $path) {
if ($error instanceof \Exception) {
$context->addError($this->buildLocatedError($error, $fieldNodes, $path));
$this->handleError(
$this->buildLocatedError($error, $fieldNodes, $path)
);
} else {
$context->addError(
$this->handleError(
$this->buildLocatedError(
new ExecutionException($error ?? 'An unknown error occurred.'),
$fieldNodes,
Expand Down Expand Up @@ -366,6 +363,7 @@ public function completeValueWithLocatedError(
* @param array $fields
*
* @return array
* @throws ExecutionException
* @throws \Throwable
*/
protected function executeFields(
Expand Down Expand Up @@ -496,7 +494,6 @@ protected function completeValue(
&$result
) {
if ($result instanceof ExtendedPromiseInterface) {
/** @var ExtendedPromiseInterface $result */
return $result->then(function (&$value) use ($returnType, $fieldNodes, $info, $path) {
return $this->completeValue($returnType, $fieldNodes, $info, $path, $value);
});
Expand Down

0 comments on commit 50003e9

Please sign in to comment.