Skip to content

Commit 41059c2

Browse files
authored
Merge pull request #157 from mcg-web/fix-handling-invariant-violation-exceptions
Fix error handler to white list `GraphQL\Error\InvariantViolation`
2 parents b8bf70d + b74fecb commit 41059c2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Error/ErrorHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Overblog\GraphQLBundle\Error;
1313

1414
use GraphQL\Error\Error as GraphQLError;
15+
use GraphQL\Error\InvariantViolation;
1516
use GraphQL\Executor\ExecutionResult;
1617
use Psr\Log\LoggerInterface;
1718
use Psr\Log\LogLevel;
@@ -83,8 +84,8 @@ protected function treatExceptions(array $errors, $throwRawException)
8384
foreach ($errors as $error) {
8485
$rawException = $this->convertException($error->getPrevious());
8586

86-
// Parse error or user error
87-
if (null === $rawException) {
87+
// raw GraphQL Error or InvariantViolation exception
88+
if (null === $rawException || $rawException instanceof InvariantViolation) {
8889
$treatedExceptions['errors'][] = $error;
8990
continue;
9091
}

Tests/Error/ErrorHandlerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Overblog\GraphQLBundle\Tests\Error;
1313

1414
use GraphQL\Error\Error as GraphQLError;
15+
use GraphQL\Error\InvariantViolation;
1516
use GraphQL\Executor\ExecutionResult;
1617
use Overblog\GraphQLBundle\Error\ErrorHandler;
1718
use Overblog\GraphQLBundle\Error\UserError;
@@ -38,6 +39,7 @@ public function testMaskErrorWithThrowExceptionSetToFalse()
3839
new GraphQLError('Error with wrapped user error', null, null, null, null, new UserError('My User Error')),
3940
new GraphQLError('', null, null, null, null, new UserErrors(['My User Error 1', 'My User Error 2', new UserError('My User Error 3')])),
4041
new GraphQLError('Error with wrapped user warning', null, null, null, null, new UserWarning('My User Warning')),
42+
new GraphQLError('Invalid value!', null, null, null, null, new InvariantViolation('Invalid value!')),
4143
]
4244
);
4345

@@ -63,6 +65,9 @@ public function testMaskErrorWithThrowExceptionSetToFalse()
6365
[
6466
'message' => 'My User Error 3',
6567
],
68+
[
69+
'message' => 'Invalid value!',
70+
],
6671
],
6772
'extensions' => [
6873
'warnings' => [

0 commit comments

Comments
 (0)