-
Notifications
You must be signed in to change notification settings - Fork 53
Conversation
It doesn't fix the problem, NetworkException is thrown anyway if the request does not have a response. |
Sorry, I thought a RequestException always had a Response unless it was a TooManyRedirectsException or ConnectException. Am I correct when highlighting the network errors? |
Not sure, haven't checked yet. Ideally Network exception should be thrown when it is actually related to networking, HttpException should be thrown if we have a response, otherwise, if it is a Guzzle RequestException, our RequestException should be thrown. Not sure, if the order of conditions is right though. |
Digging in Guzzle's source there are situations where a instance of So I've updated the PR. It first checks if it is a If the request was related to Network (ie Guzzle's |
Seek is not network related: https://github.com/guzzle/guzzle/blob/master/src/Exception/SeekException.php#L7 TransferException should be converted to our own TransferException, but make sure that it is the last as it is a base exception for all others. I wonder if TooMany redirects is Network exception. It is a configurable thing how many redirects are supposed to be treated invalid, not sure if it is enabled by default. @php-http/owners WDYT? Please also add some tests to make sure that every scenario is taken care of. |
Sure, I've added some test. I don't catch
|
We have our own TransferException which does not have a Request object. We still can convert a SeekException to Request exception as we have the Request, even if the exception doesn't, can't we? |
Our TransferException is an abstract class so I can't use it at the moment. Should I change it to a normal class?
You are correct.. Will do. |
@dbu AFAIK you changed it to abstract. This is a case when we could use it. Should we change it back or add a separate exception for cases like this? This would probably only make sense if we can expect TransferException thrown from Guzzle at all. |
We do not expect TransferException. Guzzle only extend it with the RequestException. class RequestException extends TransferException {} |
if there is a use case that makes sense and does not warrant a more specific exception, sure lets make it concrete. |
I do not believe we ever going to catch a TransferException if we already are catching RequestExceptions. I've updated the PR. |
Transfer exceptions does not necessarily have a Request context, while SeekException definitely have. Transfer exceptions should be converted into our TransferException (which is a concrete class again from now) I think TooManyRedirects should also be converted to an HttpException (or not converted at all). I've already expressed why it can't simply be a Network issue. Also, I find the processing logic a bit weird, I would follow something like this:
Seek exception is the only hard thing I think, but as I can see you already solved it without a convert method usage. 👍 for the separate catch statements and separate conversion methods, I like that solution. |
will TooManyRedirect show the first or the last response? oh, and is
there any place where we control limit of redirections? or is that
client specific and for adapters in the injected client?
|
I think TooManyRedirections should be handled in a plugin. Not sure if TooManyRedirections is thrown by default without specific configuration, I hope not. |
well, if the client does follow redirects, a plugin will never see them. if
not, a plugin is the right way. either way, following redirects without
limit is a reciepie for desaster, i would always want some limit.
|
There is an issue that we have not discussed here. TooManyRedirectsException does not have a response at all. I do not convert TooManyRedirectsException at all ATM. I can not convert it to a HttpException since it requires a response. |
not sure how much we care about the response in that case. if guzzle has
non, use a general network exception.
we need to have an idea who follows redirects: the guzzle client or a
plugin by php-http? guess it depends how you config guzzle. perf wise
guzzle is probably less overhead, but a php-http plugin will be more
consistent across implementations. we cant do more than recommend one or
the other way
|
throw $this->createException($e); | ||
} catch (Guzzle\SeekException $e) { | ||
throw new RequestException($e->getMessage(), $request, $e); | ||
} catch (Guzzle\TransferException $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should catch all other GuzzleExceptions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guzzle got 2 types of Exceptions. SeekException and TransferException. Both are implementing GuzzleException. Logically the same but sure, I'll make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case they introduce new ones. Also, I am not sure that plugins don't introduce do that.
@dbu I asked @Nyholm not to convert TooManyRedirects to a Network exception. I believe it is not really a network problem. If something, then a RequestException (if we cannot assume that we have a response, which is weird, because a Response is necessary in order to detect the fact of redirection. But guzzle might not inject the response into the request. I think we should have this functionality in a plugin. Probably we should mention in the plugin docs, that it is recommended NOT to use any further redirection detection in the underlying client. |
@sagikazarmark agreed: recommend to use plugin. if not plugin is used, catch the guzzle exception to wrap it into one of ours. (maybe in the generic catch-all thing rather than specifically - there are probably more cases of guzzle throwing some exceptions we do not explicitly want to handle) |
Why? I think we want to catch all exceptions. Maybe in case of adapters we could introduce an UnexpectedAdapterException to indicate that this couldn't be handled. But rather not, as we would have to introduce an adapter-utils package and it seems like an overkill for just one exception. |
oh yes, we want to catch all exceptions and wrap them. with "explicitly" i mean that we won't handle every single case of guzzle exception specifically, but just convert it into our basic exception. regarding UnexpectedAdapterException i would not do that, using the basic RequestException and having a message that explains the adapter threw some exception we did not specifically handle should be enough. |
Agree. By removing the check for TooManyRedirect should end up in a RequestException. |
Previous version of this adapter also set the guzzle client to use response instead of exception (like for 500 / 404 / ....) shouldn't we reintroduce that (so we can keep same behavior across adapters) ? It was delete by the removal of the options parameter in the adapter. |
Good question. What is the default behavior? Throwing exceptions or not? If not, then I am not sure we should do that. We should just remind the user that it is our task. If throwing exceptions is the default behavior then we should consider it. |
That is correct
The default behavior is to throw exceptions. Ref. about exceptions and parameters. |
} | ||
} | ||
|
||
/** | ||
* Converts a Guzzle exception into an Httplug exception. | ||
* | ||
* @param RequestException $exception | ||
* @param GuzzleExceptions\TransferException $exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, updating.
I added a few more comments. After that, it should be fine. Can you also please squash commits? |
Also, do you know why tests are failing? |
@dbu Have you updated the MessageFactory usage in integration tests? |
The tests are failing because I try to instantiate an abstract TransferException. |
As I can see, the tests are also failing because of php-http/adapter-integration-tests#12 |
Is that a bug in composer? The min-stability is dev. Shouldn't it always prefer 1.0.x-dev before 1.0.0-alpha |
Change the constraint to dev-master for now. |
There you go. |
Awesome, thanks @Nyholm |
Improve exception conversion, closes #8
by default, it does prefer-stable: true, which means if there is a valid version, it takes that over 1.0.x-dev. you could limit to > alpha1 or set prefer-stable: false. |
Thank you for the feedback and for merging.
Okey, thank you. |
This is an overview over the exceptions in Guzzle6. All exception implement
GuzzleException
.