Skip to content

Commit 91b025d

Browse files
committed
changing error format to follow graphql spec
1 parent 5646620 commit 91b025d

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

features/graphql/authorization.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: Authorization checking
1818
Then the response status code should be 200
1919
And the response should be in JSON
2020
And the header "Content-Type" should be equal to "application/json"
21-
And the JSON node "errors[0].status" should be equal to 403
21+
And the JSON node "errors[0].extensions.status" should be equal to 403
2222
And the JSON node "errors[0].extensions.category" should be equal to user
2323
And the JSON node "errors[0].message" should be equal to "Access Denied."
2424

@@ -40,7 +40,7 @@ Feature: Authorization checking
4040
Then the response status code should be 200
4141
And the response should be in JSON
4242
And the header "Content-Type" should be equal to "application/json"
43-
And the JSON node "errors[0].status" should be equal to 403
43+
And the JSON node "errors[0].extensions.status" should be equal to 403
4444
And the JSON node "errors[0].extensions.category" should be equal to user
4545
And the JSON node "errors[0].message" should be equal to "Access Denied."
4646

@@ -83,7 +83,7 @@ Feature: Authorization checking
8383
And the response should be in JSON
8484
And the header "Content-Type" should be equal to "application/json"
8585
And the JSON node "data.securedDummies" should be null
86-
And the JSON node "errors[0].status" should be equal to 403
86+
And the JSON node "errors[0].extensions.status" should be equal to 403
8787
And the JSON node "errors[0].extensions.category" should be equal to user
8888
And the JSON node "errors[0].message" should be equal to "Access Denied."
8989

@@ -102,7 +102,7 @@ Feature: Authorization checking
102102
Then the response status code should be 200
103103
And the response should be in JSON
104104
And the header "Content-Type" should be equal to "application/json"
105-
And the JSON node "errors[0].status" should be equal to 403
105+
And the JSON node "errors[0].extensions.status" should be equal to 403
106106
And the JSON node "errors[0].extensions.category" should be equal to user
107107
And the JSON node "errors[0].message" should be equal to "Only admins can create a secured dummy."
108108

@@ -159,7 +159,7 @@ Feature: Authorization checking
159159
Then the response status code should be 200
160160
And the response should be in JSON
161161
And the header "Content-Type" should be equal to "application/json"
162-
And the JSON node "errors[0].status" should be equal to 403
162+
And the JSON node "errors[0].extensions.status" should be equal to 403
163163
And the JSON node "errors[0].extensions.category" should be equal to user
164164
And the JSON node "errors[0].message" should be equal to "Access Denied."
165165

@@ -196,7 +196,7 @@ Feature: Authorization checking
196196
Then the response status code should be 200
197197
And the response should be in JSON
198198
And the header "Content-Type" should be equal to "application/json"
199-
And the JSON node "errors[0].status" should be equal to 403
199+
And the JSON node "errors[0].extensions.status" should be equal to 403
200200
And the JSON node "errors[0].extensions.category" should be equal to user
201201
And the JSON node "errors[0].message" should be equal to "Access Denied."
202202

features/graphql/introspection.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Feature: GraphQL introspection support
66
Then the response status code should be 200
77
And the response should be in JSON
88
And the header "Content-Type" should be equal to "application/json"
9-
And the JSON node "errors[0].status" should be equal to 400
9+
And the JSON node "errors[0].extensions.status" should be equal to 400
1010
And the JSON node "errors[0].extensions.category" should be equal to user
1111
And the JSON node "errors[0].message" should be equal to "GraphQL query is not valid."
1212

features/graphql/mutation.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,11 @@ Feature: GraphQL mutation support
674674
Then the response status code should be 200
675675
And the response should be in JSON
676676
And the header "Content-Type" should be equal to "application/json"
677-
And the JSON node "errors[0].status" should be equal to "400"
677+
And the JSON node "errors[0].extensions.status" should be equal to "400"
678678
And the JSON node "errors[0].message" should be equal to "name: This value should not be blank."
679-
And the JSON node "errors[0].violations" should exist
680-
And the JSON node "errors[0].violations[0].path" should be equal to "name"
681-
And the JSON node "errors[0].violations[0].message" should be equal to "This value should not be blank."
679+
And the JSON node "errors[0].extensions.violations" should exist
680+
And the JSON node "errors[0].extensions.violations[0].path" should be equal to "name"
681+
And the JSON node "errors[0].extensions.violations[0].message" should be equal to "This value should not be blank."
682682

683683
Scenario: Execute a custom mutation
684684
Given there are 1 dummyCustomMutation objects

src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function normalize($object, $format = null, array $context = []): array
3636
$httpException = $object->getPrevious();
3737
$error = FormattedError::createFromException($object);
3838
$error['message'] = $httpException->getMessage();
39-
$error['status'] = $statusCode = $httpException->getStatusCode();
39+
$error['extensions']['status'] = $statusCode = $httpException->getStatusCode();
4040
$error['extensions']['category'] = $statusCode < 500 ? 'user' : Error::CATEGORY_INTERNAL;
4141

4242
return $error;

src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public function normalize($object, $format = null, array $context = []): array
3939
$validationException = $object->getPrevious();
4040
$error = FormattedError::createFromException($object);
4141
$error['message'] = $validationException->getMessage();
42-
$error['status'] = Response::HTTP_BAD_REQUEST;
42+
$error['extensions']['status'] = Response::HTTP_BAD_REQUEST;
4343
$error['extensions']['category'] = 'user';
44-
$error['violations'] = [];
44+
$error['extensions']['violations'] = [];
4545

4646
/** @var ConstraintViolation $violation */
4747
foreach ($validationException->getConstraintViolationList() as $violation) {
48-
$error['violations'][] = [
48+
$error['extensions']['violations'][] = [
4949
'path' => $violation->getPropertyPath(),
5050
'message' => $violation->getMessage(),
5151
];

tests/GraphQl/Serializer/Exception/HttpExceptionNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testNormalize(HttpException $exception, string $expectedExceptio
4646

4747
$normalizedError = $this->httpExceptionNormalizer->normalize($error);
4848
$this->assertSame($expectedExceptionMessage, $normalizedError['message']);
49-
$this->assertSame($expectedStatus, $normalizedError['status']);
49+
$this->assertSame($expectedStatus, $normalizedError['extensions']['status']);
5050
$this->assertSame($expectedCategory, $normalizedError['extensions']['category']);
5151
}
5252

tests/GraphQl/Serializer/Exception/ValidationExceptionNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function testNormalize(): void
4848

4949
$normalizedError = $this->validationExceptionNormalizer->normalize($error);
5050
$this->assertSame($exceptionMessage, $normalizedError['message']);
51-
$this->assertSame(400, $normalizedError['status']);
51+
$this->assertSame(400, $normalizedError['extensions']['status']);
5252
$this->assertSame('user', $normalizedError['extensions']['category']);
53-
$this->assertArrayHasKey('violations', $normalizedError);
53+
$this->assertArrayHasKey('violations', $normalizedError['extensions']);
5454
$this->assertSame([
5555
[
5656
'path' => 'field 1',
@@ -60,7 +60,7 @@ public function testNormalize(): void
6060
'path' => 'field 2',
6161
'message' => 'message 2',
6262
],
63-
], $normalizedError['violations']);
63+
], $normalizedError['extensions']['violations']);
6464
}
6565

6666
public function testSupportsNormalization(): void

0 commit comments

Comments
 (0)