-
Notifications
You must be signed in to change notification settings - Fork 53
Exceptions thrown in chained promises are wrapped #47
Description
Q | A |
---|---|
Bug? | yes |
New Feature? | no |
Version | v1.1.1 |
Actual Behavior
When chaining a promise and throwing an exception, the exception is wrapped inside an Exception
with the message Invalid exception returned from Guzzle6
.
Expected Behavior
That my exception is thrown directly.
Steps to Reproduce
$httpClient->sendAsyncRequest(new Request('GET', 'https://www.example.com/'))
->then(function (ResponseInterface $response) {
throw new \Exception('Some problem');
})
->wait();
... results in a RuntimeException
with the message Invalid exception returned from Guzzle6
(with my Exception
as previous
).
Possible Solutions
The exception wrapping only makes sense when the actual request is being made (anything beyond that is not Guzzle). Either then return a different promise type in Promise::then()
guzzle6-adapter/src/Promise.php
Line 79 in a56941f
return new static($this->promise->then($onFulfilled, $onRejected), $this->request); |
guzzle6-adapter/src/Promise.php
Lines 64 to 68 in a56941f
} elseif ($reason instanceof \Exception) { | |
$this->exception = new \RuntimeException('Invalid exception returned from Guzzle6', 0, $reason); | |
} else { | |
$this->exception = new \UnexpectedValueException('Reason returned from Guzzle6 must be an Exception', 0, $reason); | |
} |
(Related, this will also hide any fatal errors (eg TypeError
) behind the meaningless 'Reason returned from Guzzle6 must be an Exception' exception.)