Skip to content

Commit fa37c1e

Browse files
authored
fix(state): error xml format output (#7273)
1 parent 3ed6f30 commit fa37c1e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/State/ApiResource/Error.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
errors: [],
3737
name: '_api_errors_problem',
3838
routeName: '_api_errors',
39-
outputFormats: ['json' => ['application/problem+json', 'application/json']],
39+
outputFormats: [
40+
'json' => ['application/problem+json', 'application/json'],
41+
'xml' => ['application/xml', 'text/xml'],
42+
],
4043
hideHydraOperation: true,
4144
normalizationContext: [
4245
SchemaFactory::OPENAPI_DEFINITION_NAME => '',

tests/Functional/ErrorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,21 @@ public function testJsonError(): void
9191
$this->assertResponseStatusCodeSame(415);
9292
$this->assertJsonContains(['detail' => 'The content-type "application/json" is not supported. Supported MIME types are "application/xml".']);
9393
}
94+
95+
public function testXmlError(): void
96+
{
97+
self::createClient()->request('GET', '/notfound', [
98+
'headers' => ['accept' => 'text/xml'],
99+
]);
100+
101+
$this->assertResponseStatusCodeSame(404);
102+
$this->assertResponseHeaderSame('content-type', 'application/xml; charset=utf-8');
103+
104+
self::createClient()->request('GET', '/notfound', [
105+
'headers' => ['accept' => 'application/xml'],
106+
]);
107+
108+
$this->assertResponseStatusCodeSame(404);
109+
$this->assertResponseHeaderSame('content-type', 'application/xml; charset=utf-8');
110+
}
94111
}

0 commit comments

Comments
 (0)