From 76fa884319106971559850f9629033588ab047c6 Mon Sep 17 00:00:00 2001 From: Malcolm Fell Date: Wed, 9 Sep 2020 19:45:36 +1200 Subject: [PATCH] [HttpClient] Fix Array to string conversion notice when parsing JSON error body with non-scalar detail property --- .../Exception/HttpExceptionTrait.php | 3 ++- .../Exception/HttpExceptionTraitTest.php | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php b/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php index 76e650934b134..5b7b44830722c 100644 --- a/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php +++ b/src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php @@ -60,7 +60,8 @@ public function __construct(ResponseInterface $response) // see http://www.hydra-cg.com/spec/latest/core/#description-of-http-status-codes-and-errors $separator = isset($body['hydra:title'], $body['hydra:description']) ? "\n\n" : ''; $message = ($body['hydra:title'] ?? '').$separator.($body['hydra:description'] ?? ''); - } elseif (isset($body['title']) || isset($body['detail'])) { + } elseif ((isset($body['title']) || isset($body['detail'])) + && (is_scalar($body['title'] ?? '') && is_scalar($body['detail'] ?? ''))) { // see RFC 7807 and https://jsonapi.org/format/#error-objects $separator = isset($body['title'], $body['detail']) ? "\n\n" : ''; $message = ($body['title'] ?? '').$separator.($body['detail'] ?? ''); diff --git a/src/Symfony/Component/HttpClient/Tests/Exception/HttpExceptionTraitTest.php b/src/Symfony/Component/HttpClient/Tests/Exception/HttpExceptionTraitTest.php index ac6c30df1f501..c2771cc3ae0a5 100644 --- a/src/Symfony/Component/HttpClient/Tests/Exception/HttpExceptionTraitTest.php +++ b/src/Symfony/Component/HttpClient/Tests/Exception/HttpExceptionTraitTest.php @@ -22,15 +22,24 @@ class HttpExceptionTraitTest extends TestCase { public function provideParseError(): iterable { - yield ['application/ld+json', '{"hydra:title": "An error occurred", "hydra:description": "Some details"}']; - yield ['application/problem+json', '{"title": "An error occurred", "detail": "Some details"}']; - yield ['application/vnd.api+json', '{"title": "An error occurred", "detail": "Some details"}']; + $errorWithoutMessage = 'HTTP/1.1 400 Bad Request returned for "http://example.com".'; + + $errorWithMessage = <<createMock(ResponseInterface::class); $response @@ -47,12 +56,7 @@ public function testParseError(string $mimeType, string $json): void $e = new TestException($response); $this->assertSame(400, $e->getCode()); - $this->assertSame(<<getMessage()); + $this->assertSame($expectedMessage, $e->getMessage()); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy