Skip to content

Commit

Permalink
Merge pull request #84 from OwlyCode/php7-errors-handling
Browse files Browse the repository at this point in the history
Added compatibility with php7 error handling
  • Loading branch information
vladar committed Jan 14, 2017
2 parents 5be0944 + d022b19 commit ddea764
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Error/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public static function createLocatedError($error, $nodes = null, $path = null)
} else if ($error instanceof \Exception) {
$message = $error->getMessage();
$originalError = $error;
} else if ($error instanceof \Error) {
$message = $error->getMessage();
$originalError = $error;
} else {
$message = (string) $error;
}
Expand Down Expand Up @@ -119,9 +122,9 @@ public static function formatError(Error $error)
* @param Source $source
* @param array|null $positions
* @param array|null $path
* @param \Exception $previous
* @param \Exception|\Error $previous
*/
public function __construct($message, $nodes = null, Source $source = null, $positions = null, $path = null, \Exception $previous = null)
public function __construct($message, $nodes = null, Source $source = null, $positions = null, $path = null, $previous = null)
{
parent::__construct($message, 0, $previous);

Expand Down
9 changes: 9 additions & 0 deletions src/Executor/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ private function resolveOrError($fieldDef, $fieldNode, $resolveFn, $source, $con
return $resolveFn($source, $args, $context, $info);
} catch (\Exception $error) {
return $error;
} catch (\Error $error) {
return $error;
}
}

Expand Down Expand Up @@ -778,6 +780,8 @@ public function completeValueWithLocatedError(
return $completed;
} catch (\Exception $error) {
throw Error::createLocatedError($error, $fieldNodes, $path);
} catch (\Error $error) {
throw Error::createLocatedError($error, $fieldNodes, $path);
}
}

Expand Down Expand Up @@ -810,6 +814,7 @@ public function completeValueWithLocatedError(
* @return array|null|Promise
* @throws Error
* @throws \Exception
* @throws \Error
*/
private function completeValue(
Type $returnType,
Expand All @@ -835,6 +840,10 @@ private function completeValue(
throw $result;
}

if ($result instanceof \Error) {
throw $result;
}

// If field type is NonNull, complete for inner type, and throw field error
// if result is null.
if ($returnType instanceof NonNull) {
Expand Down

0 comments on commit ddea764

Please sign in to comment.