Skip to content

Commit b5f86fe

Browse files
committed
Disables caching of invalid json
1 parent 15f147a commit b5f86fe

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/Service/Decoder/JsonResponseDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getDecodedResponse(Request $request)
5252
}
5353

5454
if (json_last_error() !== JSON_ERROR_NONE) {
55-
$decodedResponse = $response->getBody()->getContents();
55+
return $response->getBody()->getContents();
5656
}
5757

5858
if ($this->cacheEndpoint) {

tests/Service/Decoder/JsonResponseDecoderTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public function testGetDecodedResponseThrowsNetworkExceptionWhenClientFailsAndNo
145145
}
146146

147147
/**
148-
* @todo this seems like a bug, we should not store in the cache invalid json? should we throw an error?
149148
* @throws \Http\Client\Exception
150149
* @throws \Psr\SimpleCache\InvalidArgumentException
151150
*/
@@ -159,7 +158,7 @@ public function testGetDecodedResponseReturnsBodyWhenJsonDecodingFails()
159158
$response->getBody()->willReturn($this->getResponseBodyStub('{invalid_json'));
160159

161160
$this->client->sendRequest($request)->willReturn($response->reveal());
162-
$this->simpleCache->set('4429b090fd82239e188859ae626162e5e790b4db', '{invalid_json')->shouldBeCalledOnce();
161+
$this->simpleCache->set('4429b090fd82239e188859ae626162e5e790b4db', '{invalid_json')->shouldNotBeCalled();
163162

164163
$this->assertSame(
165164
'{invalid_json',

0 commit comments

Comments
 (0)