diff --git a/src/State/ApiResource/Error.php b/src/State/ApiResource/Error.php index d2c017d572c..82b2054be3c 100644 --- a/src/State/ApiResource/Error.php +++ b/src/State/ApiResource/Error.php @@ -36,7 +36,10 @@ errors: [], name: '_api_errors_problem', routeName: '_api_errors', - outputFormats: ['json' => ['application/problem+json', 'application/json']], + outputFormats: [ + 'json' => ['application/problem+json', 'application/json'], + 'xml' => ['application/xml', 'text/xml'], + ], hideHydraOperation: true, normalizationContext: [ SchemaFactory::OPENAPI_DEFINITION_NAME => '', diff --git a/tests/Functional/ErrorTest.php b/tests/Functional/ErrorTest.php index 7893b1e9241..7fdbeed3219 100644 --- a/tests/Functional/ErrorTest.php +++ b/tests/Functional/ErrorTest.php @@ -91,4 +91,21 @@ public function testJsonError(): void $this->assertResponseStatusCodeSame(415); $this->assertJsonContains(['detail' => 'The content-type "application/json" is not supported. Supported MIME types are "application/xml".']); } + + public function testXmlError(): void + { + self::createClient()->request('GET', '/notfound', [ + 'headers' => ['accept' => 'text/xml'], + ]); + + $this->assertResponseStatusCodeSame(404); + $this->assertResponseHeaderSame('content-type', 'application/xml; charset=utf-8'); + + self::createClient()->request('GET', '/notfound', [ + 'headers' => ['accept' => 'application/xml'], + ]); + + $this->assertResponseStatusCodeSame(404); + $this->assertResponseHeaderSame('content-type', 'application/xml; charset=utf-8'); + } }