|
| 1 | +@!mongodb |
1 | 2 | Feature: Error handling
|
2 | 3 | In order to be able to handle error client side
|
3 | 4 | As a client software developer
|
4 | 5 | I need to retrieve an Hydra serialization of errors
|
| 6 | + That is compatible with the JSON Problem specification |
5 | 7 |
|
6 |
| - Scenario: Get an error |
| 8 | + Scenario: Get an rfc 7807 error |
7 | 9 | When I add "Content-Type" header equal to "application/ld+json"
|
8 |
| - And I send a "POST" request to "/dummies" with body: |
| 10 | + And I send a "POST" request to "/exception_problems" with body: |
9 | 11 | """
|
10 | 12 | {}
|
11 | 13 | """
|
12 |
| - Then the response status code should be 422 |
13 |
| - And the response should be in JSON |
14 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
15 |
| - And the JSON should be equal to: |
16 |
| - """ |
17 |
| - { |
18 |
| - "@context": "/contexts/ConstraintViolationList", |
19 |
| - "@type": "ConstraintViolationList", |
20 |
| - "hydra:title": "An error occurred", |
21 |
| - "hydra:description": "name: This value should not be blank.", |
22 |
| - "violations": [ |
23 |
| - { |
24 |
| - "propertyPath": "name", |
25 |
| - "message": "This value should not be blank.", |
26 |
| - "code": "c1051bb4-d103-4f74-8988-acbcafc7fdc3" |
27 |
| - } |
28 |
| - ] |
29 |
| - } |
30 |
| - """ |
31 |
| - |
32 |
| - Scenario: Get an error during deserialization of simple relation |
33 |
| - When I add "Content-Type" header equal to "application/ld+json" |
34 |
| - And I send a "POST" request to "/dummies" with body: |
35 |
| - """ |
36 |
| - { |
37 |
| - "name": "Foo", |
38 |
| - "relatedDummy": { |
39 |
| - "name": "bar" |
40 |
| - } |
41 |
| - } |
42 |
| - """ |
43 | 14 | Then the response status code should be 400
|
44 | 15 | And the response should be in JSON
|
45 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
46 |
| - And the JSON node "@context" should be equal to "/contexts/Error" |
47 |
| - And the JSON node "@type" should be equal to "hydra:Error" |
| 16 | + And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8" |
| 17 | + And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"' |
| 18 | + And the JSON node "type" should exist |
| 19 | + And the JSON node "title" should be equal to "An error occurred" |
48 | 20 | And the JSON node "hydra:title" should be equal to "An error occurred"
|
49 |
| - And the JSON node "hydra:description" should be equal to 'Nested documents for attribute "relatedDummy" are not allowed. Use IRIs instead.' |
| 21 | + And the JSON node "detail" should exist |
| 22 | + And the JSON node "hydra:description" should exist |
50 | 23 | And the JSON node "trace" should exist
|
| 24 | + And the JSON node "status" should exist |
| 25 | + And the JSON node "@context" should not exist |
51 | 26 |
|
52 |
| - Scenario: Get an error during deserialization of collection |
| 27 | + Scenario: Get validation constraint violations |
53 | 28 | When I add "Content-Type" header equal to "application/ld+json"
|
54 |
| - And I send a "POST" request to "/dummies" with body: |
| 29 | + And I send a "POST" request to "/dummy_problems" with body: |
55 | 30 | """
|
56 |
| - { |
57 |
| - "name": "Foo", |
58 |
| - "relatedDummies": [{ |
59 |
| - "name": "bar" |
60 |
| - }] |
61 |
| - } |
| 31 | + {} |
62 | 32 | """
|
63 |
| - Then the response status code should be 400 |
| 33 | + Then the response status code should be 422 |
64 | 34 | And the response should be in JSON
|
65 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
66 |
| - And the JSON node "@context" should be equal to "/contexts/Error" |
67 |
| - And the JSON node "@type" should be equal to "hydra:Error" |
68 |
| - And the JSON node "hydra:title" should be equal to "An error occurred" |
69 |
| - And the JSON node "hydra:description" should be equal to 'Nested documents for attribute "relatedDummies" are not allowed. Use IRIs instead.' |
70 |
| - And the JSON node "trace" should exist |
71 |
| - |
72 |
| - Scenario: Get an error because of an invalid JSON |
73 |
| - When I add "Content-Type" header equal to "application/ld+json" |
74 |
| - And I send a "POST" request to "/dummies" with body: |
| 35 | + And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8" |
| 36 | + And the JSON should be equal to: |
75 | 37 | """
|
76 | 38 | {
|
77 |
| - "name": "Foo", |
78 |
| - } |
79 |
| - """ |
80 |
| - Then the response status code should be 400 |
81 |
| - And the response should be in JSON |
82 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
83 |
| - And the JSON node "@context" should be equal to "/contexts/Error" |
84 |
| - And the JSON node "@type" should be equal to "hydra:Error" |
85 |
| - And the JSON node "hydra:title" should be equal to "An error occurred" |
86 |
| - And the JSON node "hydra:description" should exist |
87 |
| - And the JSON node "trace" should exist |
88 |
| - |
89 |
| - Scenario: Get an error during update of an existing resource with a non-allowed update operation |
90 |
| - When I add "Content-Type" header equal to "application/ld+json" |
91 |
| - And I send a "POST" request to "/dummies" with body: |
92 |
| - """ |
93 |
| - { |
94 |
| - "@id": "/dummies/1", |
95 |
| - "name": "Foo" |
| 39 | + "@id": "/validation_errors/c1051bb4-d103-4f74-8988-acbcafc7fdc3", |
| 40 | + "@type": "ConstraintViolationList", |
| 41 | + "status": 422, |
| 42 | + "violations": [ |
| 43 | + { |
| 44 | + "propertyPath": "name", |
| 45 | + "message": "This value should not be blank.", |
| 46 | + "code": "c1051bb4-d103-4f74-8988-acbcafc7fdc3" |
| 47 | + } |
| 48 | + ], |
| 49 | + "detail": "name: This value should not be blank.", |
| 50 | + "hydra:title": "An error occurred", |
| 51 | + "hydra:description": "name: This value should not be blank.", |
| 52 | + "type": "/validation_errors/c1051bb4-d103-4f74-8988-acbcafc7fdc3", |
| 53 | + "title": "An error occurred" |
96 | 54 | }
|
97 |
| - """ |
98 |
| - Then the response status code should be 400 |
99 |
| - And the response should be in JSON |
100 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
101 |
| - And the JSON node "@context" should be equal to "/contexts/Error" |
102 |
| - And the JSON node "@type" should be equal to "hydra:Error" |
103 |
| - And the JSON node "hydra:title" should be equal to "An error occurred" |
104 |
| - And the JSON node "hydra:description" should be equal to "Update is not allowed for this operation." |
105 |
| - And the JSON node "trace" should exist |
106 |
| - |
107 |
| - @createSchema |
108 |
| - Scenario: Populate database with related dummies. Check that id will be "/related_dummies/1" |
109 |
| - Given I add "Content-Type" header equal to "application/ld+json" |
110 |
| - And I send a "POST" request to "/related_dummies" with body: |
111 |
| - """ |
112 |
| - { |
113 |
| - "@type": "https://schema.org/Product", |
114 |
| - "symfony": "laravel" |
115 |
| - } |
116 |
| - """ |
117 |
| - Then the response status code should be 201 |
118 |
| - And the response should be in JSON |
119 |
| - And the JSON node "@id" should be equal to "/related_dummies/1" |
120 |
| - And the JSON node "symfony" should be equal to "laravel" |
121 |
| - |
122 |
| - Scenario: Do not get an error during update of an existing relation with a non-allowed update operation |
123 |
| - When I add "Content-Type" header equal to "application/ld+json" |
124 |
| - And I send a "POST" request to "/relation_embedders" with body: |
125 |
| - """ |
126 |
| - { |
127 |
| - "anotherRelated": { |
128 |
| - "@id": "/related_dummies/1", |
129 |
| - "@type": "https://schema.org/Product", |
130 |
| - "symfony": "phalcon" |
131 |
| - } |
132 |
| - } |
133 |
| - """ |
134 |
| - Then the response status code should be 201 |
135 |
| - And the response should be in JSON |
136 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
137 |
| - And the JSON node "@context" should be equal to "/contexts/RelationEmbedder" |
138 |
| - And the JSON node "@type" should be equal to "RelationEmbedder" |
139 |
| - And the JSON node "@id" should be equal to "/relation_embedders/1" |
140 |
| - And the JSON node "anotherRelated.@id" should be equal to "/related_dummies/1" |
141 |
| - And the JSON node "anotherRelated.symfony" should be equal to "phalcon" |
142 |
| - |
143 |
| - Scenario: Get an error because of sending bad type property |
144 |
| - When I add "Content-Type" header equal to "application/json" |
145 |
| - And I send a "POST" request to "/greetings" with body: |
146 |
| - """ |
147 |
| - { |
148 |
| - "0": 1 |
149 |
| - } |
150 | 55 | """
|
151 |
| - Then the response status code should be 201 |
152 |
| - And the response should be in JSON |
153 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
154 | 56 |
|
155 |
| - Scenario: Get an rfc 7807 validation error |
| 57 | + Scenario: Get an rfc 7807 bad request error |
156 | 58 | When I add "Content-Type" header equal to "application/ld+json"
|
157 |
| - And I send a "POST" request to "/validation_exception_problems" with body: |
| 59 | + And I send a "POST" request to "/exception_problems" with body: |
158 | 60 | """
|
159 | 61 | {}
|
160 | 62 | """
|
161 |
| - Then the response status code should be 422 |
| 63 | + Then the response status code should be 400 |
162 | 64 | And the response should be in JSON
|
163 | 65 | And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
|
164 | 66 | And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
|
165 | 67 | And the JSON node "@context" should not exist
|
| 68 | + And the JSON node "type" should exist |
| 69 | + And the JSON node "title" should be equal to "An error occurred" |
| 70 | + And the JSON node "detail" should exist |
166 | 71 |
|
167 |
| - Scenario: Get an rfc 7807 error |
| 72 | + Scenario: Get an rfc 7807 validation error |
168 | 73 | When I add "Content-Type" header equal to "application/ld+json"
|
169 |
| - And I send a "POST" request to "/exception_problems" with body: |
| 74 | + And I send a "POST" request to "/validation_exception_problems" with body: |
170 | 75 | """
|
171 | 76 | {}
|
172 | 77 | """
|
173 |
| - Then the response status code should be 400 |
| 78 | + Then the response status code should be 422 |
174 | 79 | And the response should be in JSON
|
175 | 80 | And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
|
176 | 81 | And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
|
177 | 82 | And the JSON node "@context" should not exist
|
| 83 | + And the JSON node "type" should exist |
| 84 | + And the JSON node "title" should be equal to "An error occurred" |
| 85 | + And the JSON node "detail" should exist |
| 86 | + And the JSON node "violations" should exist |
178 | 87 |
|
179 |
| - Scenario: Get an rfc 7807 error with backward compatibility |
180 |
| - When I add "Content-Type" header equal to "application/ld+json" |
181 |
| - And I send a "POST" request to "/exception_problems_with_compatibility" with body: |
182 |
| - """ |
183 |
| - {} |
184 |
| - """ |
185 |
| - Then the response status code should be 400 |
186 |
| - And the response should be in JSON |
187 |
| - And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8" |
188 |
| - And the header "Link" should not contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"' |
189 |
| - And the JSON node "@context" should exist |
0 commit comments