Skip to content

Commit 51773bd

Browse files
committed
fix: errors bc with rfc_7807_compliant_errors false
1 parent 73569fc commit 51773bd

File tree

52 files changed

+1045
-583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1045
-583
lines changed

features/hal/problem.feature

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@!mongodb
12
Feature: Error handling valid according to RFC 7807 (application/problem+json)
23
In order to be able to handle error client side
34
As a client software developer
@@ -6,7 +7,7 @@ Feature: Error handling valid according to RFC 7807 (application/problem+json)
67
Scenario: Get an error
78
When I add "Content-Type" header equal to "application/json"
89
And I add "Accept" header equal to "application/json"
9-
And I send a "POST" request to "/dummies" with body:
10+
And I send a "POST" request to "/dummy_problems" with body:
1011
"""
1112
{}
1213
"""
@@ -33,7 +34,7 @@ Feature: Error handling valid according to RFC 7807 (application/problem+json)
3334
Scenario: Get an error during deserialization of simple relation
3435
When I add "Content-Type" header equal to "application/json"
3536
And I add "Accept" header equal to "application/json"
36-
And I send a "POST" request to "/dummies" with body:
37+
And I send a "POST" request to "/dummy_problems" with body:
3738
"""
3839
{
3940
"name": "Foo",

features/hal/problem_legacy.feature

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Feature: Error handling valid according to RFC 7807 (application/problem+json)
2+
In order to be able to handle error client side
3+
As a client software developer
4+
I need to retrieve an RFC 7807 compliant serialization of errors
5+
6+
Scenario: Get an error
7+
When I add "Content-Type" header equal to "application/json"
8+
And I add "Accept" header equal to "application/json"
9+
And I send a "POST" request to "/dummies" with body:
10+
"""
11+
{}
12+
"""
13+
Then the response status code should be 422
14+
And the response should be in JSON
15+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
16+
And the JSON should be equal to:
17+
"""
18+
{
19+
"type": "https:\/\/tools.ietf.org\/html\/rfc2616#section-10",
20+
"title": "An error occurred",
21+
"detail": "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/json"
34+
And I add "Accept" header equal to "application/json"
35+
And I send a "POST" request to "/dummies" with body:
36+
"""
37+
{
38+
"name": "Foo",
39+
"relatedDummy": {
40+
"name": "bar"
41+
}
42+
}
43+
"""
44+
Then the response status code should be 400
45+
And the response should be in JSON
46+
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
47+
And the JSON node "type" should be equal to "https://tools.ietf.org/html/rfc2616#section-10"
48+
And the JSON node "title" should be equal to "An error occurred"
49+
And the JSON node "detail" should be equal to 'Nested documents for attribute "relatedDummy" are not allowed. Use IRIs instead.'
50+
And the JSON node "trace" should exist

features/hydra/error.feature

+46-148
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,87 @@
1+
@!mongodb
12
Feature: Error handling
23
In order to be able to handle error client side
34
As a client software developer
45
I need to retrieve an Hydra serialization of errors
6+
That is compatible with the JSON Problem specification
57

6-
Scenario: Get an error
8+
Scenario: Get an rfc 7807 error
79
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:
911
"""
1012
{}
1113
"""
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-
"""
4314
Then the response status code should be 400
4415
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"
4820
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
5023
And the JSON node "trace" should exist
24+
And the JSON node "status" should exist
25+
And the JSON node "@context" should not exist
5126

52-
Scenario: Get an error during deserialization of collection
27+
Scenario: Get validation constraint violations
5328
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:
5530
"""
56-
{
57-
"name": "Foo",
58-
"relatedDummies": [{
59-
"name": "bar"
60-
}]
61-
}
31+
{}
6232
"""
63-
Then the response status code should be 400
33+
Then the response status code should be 422
6434
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:
7537
"""
7638
{
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"
9654
}
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-
}
15055
"""
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"
15456

155-
Scenario: Get an rfc 7807 validation error
57+
Scenario: Get an rfc 7807 bad request error
15658
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:
15860
"""
15961
{}
16062
"""
161-
Then the response status code should be 422
63+
Then the response status code should be 400
16264
And the response should be in JSON
16365
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
16466
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
16567
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
16671

167-
Scenario: Get an rfc 7807 error
72+
Scenario: Get an rfc 7807 validation error
16873
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:
17075
"""
17176
{}
17277
"""
173-
Then the response status code should be 400
78+
Then the response status code should be 422
17479
And the response should be in JSON
17580
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
17681
And the header "Link" should contain '<http://www.w3.org/ns/hydra/error>; rel="http://www.w3.org/ns/json-ld#error"'
17782
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
17887

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

Comments
 (0)