Skip to content

Commit

Permalink
Disables caching of invalid json
Browse files Browse the repository at this point in the history
  • Loading branch information
moay committed Apr 23, 2019
1 parent 15f147a commit b5f86fe
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Service/Decoder/JsonResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getDecodedResponse(Request $request)
}

if (json_last_error() !== JSON_ERROR_NONE) {
$decodedResponse = $response->getBody()->getContents();
return $response->getBody()->getContents();
}

if ($this->cacheEndpoint) {
Expand Down
3 changes: 1 addition & 2 deletions tests/Service/Decoder/JsonResponseDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function testGetDecodedResponseThrowsNetworkExceptionWhenClientFailsAndNo
}

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

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

$this->assertSame(
'{invalid_json',
Expand Down

0 comments on commit b5f86fe

Please sign in to comment.