@@ -15,9 +15,9 @@ configure API Platform to convert it to a `404 Not Found` error:
15
15
16
16
``` php
17
17
<?php
18
- // src/AppBundle/ Exception/ProductNotFoundException.php
18
+ // src/Exception/ProductNotFoundException.php
19
19
20
- namespace AppBundle \Exception;
20
+ namespace App \Exception;
21
21
22
22
final class ProductNotFoundException extends \Exception
23
23
{
@@ -26,13 +26,13 @@ final class ProductNotFoundException extends \Exception
26
26
27
27
``` php
28
28
<?php
29
- // src/AppBundle/ EventSubscriber/CartManager.php
29
+ // src/EventSubscriber/CartManager.php
30
30
31
- namespace AppBundle \EventSubscriber;
31
+ namespace App \EventSubscriber;
32
32
33
33
use ApiPlatform\Core\EventListener\EventPriorities;
34
- use AppBundle \Entity\Product;
35
- use AppBundle \Exception\ProductNotFoundException;
34
+ use App \Entity\Product;
35
+ use App \Exception\ProductNotFoundException;
36
36
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
37
37
use Symfony\Component\HttpFoundation\Request;
38
38
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
@@ -65,7 +65,7 @@ final class ProductManager implements EventSubscriberInterface
65
65
If you use the standard distribution of API Platform, this event listener will be automatically registered. If you use a
66
66
custom installation, [ learn how to register listeners] ( events.md ) .
67
67
68
- Then, configure the framework to catch ` AppBundle \Exception\ProductNotFoundException` exceptions and convert them in ` 404 `
68
+ Then, configure the framework to catch ` App \Exception\ProductNotFoundException` exceptions and convert them in ` 404 `
69
69
errors:
70
70
71
71
``` yaml
@@ -77,7 +77,7 @@ api_platform:
77
77
Symfony\Component\Serializer\Exception\ExceptionInterface : 400 # Use a raw status code (recommended)
78
78
ApiPlatform\Core\Exception\InvalidArgumentException : ' HTTP_BAD_REQUEST' # Or a `Symfony\Component\HttpFoundation\Response`'s constant
79
79
80
- AppBundle \Exception\ProductNotFoundException : 404 # Here is the handler for our custom exception
80
+ App \Exception\ProductNotFoundException : 404 # Here is the handler for our custom exception
81
81
` ` `
82
82
83
83
Any type of ` Exception` can be thrown, API Platform will convert it to a Symfony's `HttpException`. The framework also takes
0 commit comments