Lighthouse 5.16
This commit is contained in:
+17
-14
@@ -4,28 +4,31 @@ namespace Nuwave\Lighthouse\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use GraphQL\Error\ClientAware;
|
||||
use GraphQL\Error\SyntaxError;
|
||||
use GraphQL\Language\Source;
|
||||
|
||||
class ParseException extends Exception implements ClientAware
|
||||
{
|
||||
/**
|
||||
* Returns true when exception message is safe to be displayed to a client.
|
||||
*
|
||||
* @api
|
||||
* @return bool
|
||||
*/
|
||||
public function __construct(SyntaxError $error)
|
||||
{
|
||||
$message = $error->getMessage();
|
||||
|
||||
$source = $error->getSource();
|
||||
$positions = $error->getPositions();
|
||||
if ($source instanceof Source && count($positions) > 0) {
|
||||
$position = $positions[0];
|
||||
|
||||
$message .= ', near: '.\Safe\substr($source->body, max(0, $position - 50), 100);
|
||||
}
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
public function isClientSafe(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string describing a category of the error.
|
||||
*
|
||||
* Value "graphql" is reserved for errors produced by query parsing or validation, do not use it.
|
||||
*
|
||||
* @api
|
||||
* @return string
|
||||
*/
|
||||
public function getCategory(): string
|
||||
{
|
||||
return 'schema';
|
||||
|
||||
Reference in New Issue
Block a user