-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve exception handling in Type::getDocument() #693
Conversation
Check issue #687 |
$response = $this->request($path, Request::GET, array(), $options); | ||
$result = $response->getData(); | ||
} catch (ResponseException $e) { | ||
throw new NotFoundException('doc id ' . $id . ' not found'); |
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 a BC break, you should be passing the previous exception to the new one.
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.
It is, I've upgraded it to the other proposal I did which doesn't break BC, but IMHO It doesn't seem appropiate to throw a NotFoundException for ResponseExceptions.
@rmruano I see your point. Is there an option we can actually make the difference between the two exceptions? Means, in case we get a response exception and it is a notfound, we throw this one, but in your case throw a response or a more specific exception. And if none both hits, we throw the general response exception. |
@ruflin The thing is that ES returns a 404 response code for not founds (not sure about older versions) and it doesn't return an error response, so no ResponseException is triggered and no NotFound should be ever thrown in that case. If you don't want to break BC you can merge this PR as is right now, at least the exception includes now a better message and the original exception, but I still think the ResponseException should not be catched at all (like all other methods at the Type class do). Having said that, what do you think about creating a BadRequestException extending (or not) ResponseException?, AbstractTransport::exec() methods could be updated to consider this case:
And Type::getDocument() could detect it:
Anyway, I would still remove the whole try / catch :) |
Requesting existing documents without providing a routing parameter (for types with parent docs) rise a NotFoundException which is confusing and makes debugging a lot harder.