Skip to content

Commit 965f4a0

Browse files
authored
[RELEASE][HOTFIX] Correct Stream processing with newer Guzzle versions (#14)
* [FX] Also add throwing values in rejection callbacks * [FX] Also add throwing values in rejection callbacks for CachedRegistry * [FX] Use correct stream string access in `ExceptionMap`
1 parent 4d232ec commit 965f4a0

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

src/Exception/ExceptionMap.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,29 @@ private function guardAgainstMissingResponse(RequestException $exception): Respo
6363

6464
private function guardAgainstMissingErrorCode(ResponseInterface $response): array
6565
{
66-
$decodedBody = \GuzzleHttp\json_decode($response->getBody()->getContents(), true);
67-
68-
if (!array_key_exists(self::ERROR_CODE_FIELD_NAME, $decodedBody)) {
66+
try {
67+
$decodedBody = \GuzzleHttp\json_decode((string) $response->getBody(), true);
68+
69+
if (!\array_key_exists(self::ERROR_CODE_FIELD_NAME, $decodedBody)) {
70+
throw new \RuntimeException(
71+
sprintf(
72+
'Invalid message body received - cannot find "error_code" field in response body "%s"',
73+
(string) $response->getBody()
74+
)
75+
);
76+
}
77+
78+
return $decodedBody;
79+
} catch (\Exception $e) {
6980
throw new \RuntimeException(
70-
sprintf(
81+
\sprintf(
7182
'Invalid message body received - cannot find "error_code" field in response body "%s"',
72-
$response->getBody()->getContents()
73-
)
83+
(string) $response->getBody()
84+
),
85+
$e->getCode(),
86+
$e
7487
);
7588
}
76-
77-
return $decodedBody;
7889
}
7990

8091
private function mapErrorCodeToException($errorCode, $errorMessage)

src/Registry/BlockingRegistry.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ public function latestVersion(string $subject, callable $requestCallback = null)
109109
*/
110110
private function addExceptionThrowCallableToPromise(PromiseInterface $promise): PromiseInterface
111111
{
112-
return $promise->then(
113-
function ($value) {
114-
if ($value instanceof \Exception) {
115-
throw $value;
116-
}
117-
118-
return $value;
112+
$throwingValueFunction = function ($value) {
113+
if ($value instanceof \Exception) {
114+
throw $value;
119115
}
120-
);
116+
117+
return $value;
118+
};
119+
120+
return $promise->then($throwingValueFunction, $throwingValueFunction);
121121
}
122122
}

src/Registry/CachedRegistry.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,16 @@ public function latestVersion(string $subject, callable $requestCallback = null)
169169
return $this->registry->latestVersion($subject, $requestCallback);
170170
}
171171

172-
173-
/**
174-
* {@inheritdoc}
175-
*/
176172
private function applyValueHandlers($value, callable $promiseHandler, callable $valueHandler)
177173
{
178174
if ($value instanceof PromiseInterface) {
179175
return $promiseHandler($value);
180176
}
181177

178+
if ($value instanceof \Exception) {
179+
throw $value;
180+
}
181+
182182
return $valueHandler($value);
183183
}
184184

0 commit comments

Comments
 (0)