File tree Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Expand file tree Collapse file tree 4 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -45,3 +45,8 @@ Feature: Using exception_to_status config
45
45
And I send a "GET" request to "/issue5924"
46
46
Then the response status code should be 429
47
47
Then the header "retry-after" should be equal to 32
48
+
49
+ Scenario : Show error page
50
+ When I add "Accept" header equal to "text/html"
51
+ And I send a "GET" request to "/errors/404"
52
+ Then the response status code should be 200
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the API Platform project.
5
+ *
6
+ * (c) Kévin Dunglas <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ declare (strict_types=1 );
13
+
14
+ namespace ApiPlatform \Symfony \Action ;
15
+
16
+ use Symfony \Component \HttpFoundation \Request ;
17
+ use Symfony \Component \HttpFoundation \Response ;
18
+ use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
19
+
20
+ final class ErrorPageAction
21
+ {
22
+ public function __invoke (Request $ request ): Response
23
+ {
24
+ $ status = $ request ->attributes ->get ('status ' );
25
+ $ text = Response::$ statusTexts [$ status ] ?? throw new NotFoundHttpException ();
26
+
27
+ return new Response (<<<HTML
28
+ <!DOCTYPE html>
29
+ <html>
30
+ <head>
31
+ <meta charset="UTF-8" />
32
+ <title>Error $ status</title>
33
+ </head>
34
+ <body><h1>Error $ status</h1> $ text</body>
35
+ </html>
36
+ HTML );
37
+ }
38
+ }
Original file line number Diff line number Diff line change 13
13
<service id =" api_platform.property_accessor" alias =" property_accessor" public =" false" />
14
14
<service id =" api_platform.property_info" alias =" property_info" public =" false" />
15
15
<service id =" api_platform.negotiator" class =" Negotiation\Negotiator" public =" false" />
16
+ <service id =" api_platform.action.error_page" class =" ApiPlatform\Symfony\Action\ErrorPageAction" public =" true" />
16
17
17
18
<!-- deprecated -->
18
19
<service id =" ApiPlatform\Action\NotFoundAction" alias =" api_platform.action.not_found" public =" true" />
Original file line number Diff line number Diff line change 6
6
http://symfony.com/schema/routing/routing-1.0.xsd" >
7
7
8
8
<route id =" api_errors" path =" /errors/{status}" methods =" GET|HEAD" >
9
- <default key =" _controller" >api_platform.action.not_exposed</default >
10
- <default key =" status" >500</default >
9
+ <default key =" _controller" >api_platform.action.error_page</default >
11
10
12
11
<requirement key =" status" >\d+</requirement >
13
12
</route >
You can’t perform that action at this time.
0 commit comments