Skip to content

Commit 2879cbb

Browse files
committed
[Hydra] Normalization error in ErrorNormalizer.php for Error type
1 parent 63c880f commit 2879cbb

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

features/hydra/error.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Feature: Error handling
4343
And the response should be in JSON
4444
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
4545
And the JSON node "@context" should be equal to "/contexts/Error"
46-
And the JSON node "@type" should be equal to "Error"
46+
And the JSON node "@type" should be equal to "hydra:Error"
4747
And the JSON node "hydra:title" should be equal to "An error occurred"
4848
And the JSON node "hydra:description" should be equal to 'Nested documents for attribute "relatedDummy" are not allowed. Use IRIs instead.'
4949
And the JSON node "trace" should exist
@@ -63,7 +63,7 @@ Feature: Error handling
6363
And the response should be in JSON
6464
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
6565
And the JSON node "@context" should be equal to "/contexts/Error"
66-
And the JSON node "@type" should be equal to "Error"
66+
And the JSON node "@type" should be equal to "hydra:Error"
6767
And the JSON node "hydra:title" should be equal to "An error occurred"
6868
And the JSON node "hydra:description" should be equal to 'Nested documents for attribute "relatedDummies" are not allowed. Use IRIs instead.'
6969
And the JSON node "trace" should exist
@@ -80,7 +80,7 @@ Feature: Error handling
8080
And the response should be in JSON
8181
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
8282
And the JSON node "@context" should be equal to "/contexts/Error"
83-
And the JSON node "@type" should be equal to "Error"
83+
And the JSON node "@type" should be equal to "hydra:Error"
8484
And the JSON node "hydra:title" should be equal to "An error occurred"
8585
And the JSON node "hydra:description" should exist
8686
And the JSON node "trace" should exist
@@ -98,7 +98,7 @@ Feature: Error handling
9898
And the response should be in JSON
9999
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
100100
And the JSON node "@context" should be equal to "/contexts/Error"
101-
And the JSON node "@type" should be equal to "Error"
101+
And the JSON node "@type" should be equal to "hydra:Error"
102102
And the JSON node "hydra:title" should be equal to "An error occurred"
103103
And the JSON node "hydra:description" should be equal to "Update is not allowed for this operation."
104104
And the JSON node "trace" should exist
@@ -119,7 +119,7 @@ Feature: Error handling
119119
And the response should be in JSON
120120
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
121121
And the JSON node "@context" should be equal to "/contexts/Error"
122-
And the JSON node "@type" should be equal to "Error"
122+
And the JSON node "@type" should be equal to "hydra:Error"
123123
And the JSON node "hydra:title" should be equal to "An error occurred"
124124
And the JSON node "hydra:description" should be equal to "Update is not allowed for this operation."
125125
And the JSON node "trace" should exist

features/security/strong_typing.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Feature: Handle properly invalid data submitted to the API
5151
And the response should be in JSON
5252
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
5353
And the JSON node "@context" should be equal to "/contexts/Error"
54-
And the JSON node "@type" should be equal to "Error"
54+
And the JSON node "@type" should be equal to "hydra:Error"
5555
And the JSON node "hydra:title" should be equal to "An error occurred"
5656
And the JSON node "hydra:description" should be equal to 'Expected IRI or nested document for attribute "relatedDummy", "string" given.'
5757
And the JSON node "trace" should exist
@@ -82,7 +82,7 @@ Feature: Handle properly invalid data submitted to the API
8282
And the response should be in JSON
8383
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
8484
And the JSON node "@context" should be equal to "/contexts/Error"
85-
And the JSON node "@type" should be equal to "Error"
85+
And the JSON node "@type" should be equal to "hydra:Error"
8686
And the JSON node "hydra:title" should be equal to "An error occurred"
8787
And the JSON node "hydra:description" should be equal to 'The type of the "relatedDummies" attribute must be "array", "string" given.'
8888
And the JSON node "trace" should exist
@@ -100,7 +100,7 @@ Feature: Handle properly invalid data submitted to the API
100100
And the response should be in JSON
101101
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
102102
And the JSON node "@context" should be equal to "/contexts/Error"
103-
And the JSON node "@type" should be equal to "Error"
103+
And the JSON node "@type" should be equal to "hydra:Error"
104104
And the JSON node "hydra:title" should be equal to "An error occurred"
105105
And the JSON node "hydra:description" should be equal to 'The type of the key "a" must be "int", "string" given.'
106106

@@ -116,7 +116,7 @@ Feature: Handle properly invalid data submitted to the API
116116
And the response should be in JSON
117117
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
118118
And the JSON node "@context" should be equal to "/contexts/Error"
119-
And the JSON node "@type" should be equal to "Error"
119+
And the JSON node "@type" should be equal to "hydra:Error"
120120
And the JSON node "hydra:title" should be equal to "An error occurred"
121121
And the JSON node "hydra:description" should be equal to 'The type of the "name" attribute must be "string", "integer" given.'
122122

src/Hydra/Serializer/ErrorNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function normalize($object, $format = null, array $context = [])
4646

4747
$data = [
4848
'@context' => $this->urlGenerator->generate('api_jsonld_context', ['shortName' => 'Error']),
49-
'@type' => 'Error',
49+
'@type' => 'hydra:Error',
5050
'hydra:title' => $context['title'] ?? 'An error occurred',
5151
'hydra:description' => $message ?? (string) $object,
5252
];

tests/Hydra/Serializer/ErrorNormalizerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testNormalize()
4545
$this->assertEquals(
4646
[
4747
'@context' => '/context/foo',
48-
'@type' => 'Error',
48+
'@type' => 'hydra:Error',
4949
'hydra:title' => 'An error occurred',
5050
'hydra:description' => 'Hello',
5151
],
@@ -54,7 +54,7 @@ public function testNormalize()
5454
$this->assertEquals(
5555
[
5656
'@context' => '/context/foo',
57-
'@type' => 'Error',
57+
'@type' => 'hydra:Error',
5858
'hydra:title' => 'Hi',
5959
'hydra:description' => 'Hello',
6060
],

0 commit comments

Comments
 (0)