7
7
// tags: design, state
8
8
// ---
9
9
10
- // Note that we use the following configuration:
11
- // ```
12
- // api_platform:
13
- // defaults:
14
- // rfc_7807_compliant_errors: true
15
- // ```
16
-
17
10
namespace App \ApiResource {
18
11
use ApiPlatform \Metadata \ErrorResource ;
19
12
use ApiPlatform \Metadata \Exception \ProblemExceptionInterface ;
@@ -25,12 +18,12 @@ class MyDomainException extends \Exception implements ProblemExceptionInterface
25
18
{
26
19
public function getType (): string
27
20
{
28
- return 'teapot ' ;
21
+ return '/errors/418 ' ;
29
22
}
30
23
31
24
public function getTitle (): ?string
32
25
{
33
- return null ;
26
+ return ' Teapot error ' ;
34
27
}
35
28
36
29
public function getStatus (): ?int
@@ -47,6 +40,8 @@ public function getInstance(): ?string
47
40
{
48
41
return null ;
49
42
}
43
+
44
+ public string $ myCustomField = 'I usually prefer coffee. ' ;
50
45
}
51
46
52
47
use ApiPlatform \Metadata \ApiResource ;
@@ -90,7 +85,12 @@ public function testBookDoesNotExists(): void
90
85
// you can override this by looking at the [Error Provider guide](/docs/guides/error-provider).
91
86
$ this ->assertResponseStatusCodeSame (418 );
92
87
$ this ->assertJsonContains ([
88
+ '@id ' => '/my_domain_exceptions ' ,
89
+ '@type ' => 'MyDomainException ' ,
90
+ 'type ' => '/errors/418 ' ,
91
+ 'title ' => 'Teapot error ' ,
93
92
'detail ' => 'I am teapot ' ,
93
+ 'myCustomField ' => 'I usually prefer coffee. '
94
94
]);
95
95
}
96
96
}
0 commit comments