guzzle-cache-middleware
guzzle-cache-middleware copied to clipboard
Type error: expected Exception, got string with mock + log middleware
The MockMiddleware creates a RejectedPromise with a string reason in https://github.com/csarrazi/guzzle-cache-middleware/blob/master/src/MockMiddleware.php#L47 if the cache is not found. The log middleware then fails because the MessageFormatter requires an exception in https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php#L70
It seems like a rejection reason does not necessarily need to be an exception because the reason is never typehinted in guzzle/promises. In this case the bug is more in Guzzle itself that the log middleware cannot deal with that.
Good catch @Tobion!
What we can do there is simply change the reason to be an instance of an Exception type, which could then be handled by the log handler. I'm not sure, but this may need some changes in the data collector, as I am not entirely certain about how Guzzle actually handles errors (as you mentioned, because of the missing type hint, it is a bit of a grey area).