guzzle-cache-middleware icon indicating copy to clipboard operation
guzzle-cache-middleware copied to clipboard

Type error: expected Exception, got string with mock + log middleware

Open Tobion opened this issue 6 years ago • 2 comments

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.

Tobion avatar Jan 15 '18 18:01 Tobion

Good catch @Tobion!

csarrazi avatar Jan 16 '18 13:01 csarrazi

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).

csarrazi avatar Jan 17 '18 08:01 csarrazi