diff --git a/features/main/exception_to_status.feature b/features/main/exception_to_status.feature index a182ea848a8..c77c6d59edb 100644 --- a/features/main/exception_to_status.feature +++ b/features/main/exception_to_status.feature @@ -45,3 +45,8 @@ Feature: Using exception_to_status config And I send a "GET" request to "/issue5924" Then the response status code should be 429 Then the header "retry-after" should be equal to 32 + + Scenario: Show error page + When I add "Accept" header equal to "text/html" + And I send a "GET" request to "/errors/404" + Then the response status code should be 200 diff --git a/src/Symfony/Action/ErrorPageAction.php b/src/Symfony/Action/ErrorPageAction.php new file mode 100644 index 00000000000..e1d8aab1ca7 --- /dev/null +++ b/src/Symfony/Action/ErrorPageAction.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Symfony\Action; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; + +final class ErrorPageAction +{ + public function __invoke(Request $request): Response + { + $status = $request->attributes->get('status'); + $text = Response::$statusTexts[$status] ?? throw new NotFoundHttpException(); + + return new Response(<< + + + + Error $status + +

Error $status

$text + +HTML); + } +} diff --git a/src/Symfony/Bundle/Resources/config/api.xml b/src/Symfony/Bundle/Resources/config/api.xml index 6f8f94d5075..76710938095 100644 --- a/src/Symfony/Bundle/Resources/config/api.xml +++ b/src/Symfony/Bundle/Resources/config/api.xml @@ -13,6 +13,7 @@ + diff --git a/src/Symfony/Bundle/Resources/config/routing/errors.xml b/src/Symfony/Bundle/Resources/config/routing/errors.xml index 952cd1d4d51..bcdaa358d30 100644 --- a/src/Symfony/Bundle/Resources/config/routing/errors.xml +++ b/src/Symfony/Bundle/Resources/config/routing/errors.xml @@ -6,8 +6,7 @@ http://symfony.com/schema/routing/routing-1.0.xsd"> - api_platform.action.not_exposed - 500 + api_platform.action.error_page \d+