From a50c9a4c1ff1c7bd93b5cb7183337fedf0c520cd Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Thu, 17 Aug 2017 02:13:44 +0700 Subject: [PATCH] Renamed error category constants --- src/Error/Error.php | 21 ++++++++++++++++----- src/Error/FormattedError.php | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Error/Error.php b/src/Error/Error.php index e2f3b81..4b07092 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -16,8 +16,8 @@ use GraphQL\Utils\Utils; */ class Error extends \Exception implements \JsonSerializable, ClientAware { - const GRAPHQL = 'graphql'; - const INTERNAL = 'internal'; + const CATEGORY_GRAPHQL = 'graphql'; + const CATEGORY_INTERNAL = 'internal'; /** * A message describing the Error for debugging purposes. @@ -161,13 +161,13 @@ class Error extends \Exception implements \JsonSerializable, ClientAware if ($previous instanceof ClientAware) { $this->isClientSafe = $previous->isClientSafe(); - $this->category = $previous->getCategory() ?: static::INTERNAL; + $this->category = $previous->getCategory() ?: static::CATEGORY_INTERNAL; } else if ($previous) { $this->isClientSafe = false; - $this->category = static::INTERNAL; + $this->category = static::CATEGORY_INTERNAL; } else { $this->isClientSafe = true; - $this->category = static::GRAPHQL; + $this->category = static::CATEGORY_GRAPHQL; } } @@ -239,6 +239,17 @@ class Error extends \Exception implements \JsonSerializable, ClientAware return $this->locations; } + /** + * Returns an array describing the JSON-path into the execution response which + * corresponds to this error. Only included for errors during execution. + * + * @return array|null + */ + public function getPath() + { + return $this->path; + } + /** * Returns array representation of error suitable for serialization * diff --git a/src/Error/FormattedError.php b/src/Error/FormattedError.php index 395216b..02c18b8 100644 --- a/src/Error/FormattedError.php +++ b/src/Error/FormattedError.php @@ -24,6 +24,9 @@ class FormattedError } /** + * Standard GraphQL error formatter. Converts any exception to GraphQL error + * conforming to GraphQL spec + * * @param \Throwable $e * @param bool|int $debug * @param string $internalErrorMessage @@ -56,7 +59,7 @@ class FormattedError } else { $result = [ 'message' => $internalErrorMessage, - 'category' => Error::INTERNAL + 'category' => Error::CATEGORY_INTERNAL ]; } if (($debug & self::INCLUDE_DEBUG_MESSAGE > 0) && $result['message'] === $internalErrorMessage) {