Skip to content

Commit 9cabb12

Browse files
authored
Document exception_to_status on resources and operations (#1309)
1 parent ae46061 commit 9cabb12

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/errors.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,37 @@ the error will be returned in this format as well:
100100
"hydra:description": "The product \"1234\" does not exist."
101101
}
102102
```
103+
104+
## Fine-grained Configuration
105+
106+
The `exception_to_status` configuration can be set on resources and operations:
107+
108+
```php
109+
<?php
110+
// api/src/Entity/Book.php
111+
namespace App\Entity;
112+
113+
use ApiPlatform\Core\Annotation\ApiResource;
114+
use App\Exception\ProductWasRemovedException;
115+
use App\Exception\ProductNotFoundException;
116+
117+
#[ApiResource(
118+
itemOperations: [
119+
'get' => [
120+
'exception_to_status' => [
121+
ProductWasRemovedException::class => 410,
122+
],
123+
],
124+
],
125+
exceptionToStatus: [
126+
ProductNotFoundException::class => 404,
127+
]
128+
)]
129+
class Book
130+
{
131+
// ...
132+
}
133+
```
134+
135+
Exceptions mappings defined on operations take precedence over mappings defined on resources, which take precedence over
136+
the global config.

0 commit comments

Comments
 (0)