Renamed error category constants

This commit is contained in:
Vladimir Razuvaev 2017-08-17 02:13:44 +07:00
parent 4634f214ea
commit a50c9a4c1f
2 changed files with 20 additions and 6 deletions

View File

@ -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
*

View File

@ -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) {