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
Handle Elastica Transport errors #1465
Changes from 3 commits
be5d9fe
f792d6d
2607d66
543e31f
e5386ea
3d5e889
5cc527d
7f3de79
40848c0
934f812
92e089f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
*/ | ||
class Client extends BaseClient | ||
{ | ||
private $forbiddenHttpCodes = [403, 404, 400]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make this configurable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, let me implement this and add some tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note that by intercepting
|
||
|
||
/** | ||
* Stores created indexes to avoid recreation. | ||
* | ||
|
@@ -48,8 +50,15 @@ public function request($path, $method = Request::GET, $data = [], array $query | |
} | ||
|
||
$response = parent::request($path, $method, $data, $query, $contentType); | ||
$responseData = $response->getData(); | ||
|
||
$transportInfo = $response->getTransferInfo(); | ||
if (isset($transportInfo['http_code']) && in_array($transportInfo['http_code'], $this->forbiddenHttpCodes)) { | ||
$body = isset($transportInfo['body']) ? $transportInfo['body'] : 'blank'; | ||
$message = sprintf('Error in transportInfo: response code is %s, response body is %s', $transportInfo['http_code'], $body); | ||
throw new \Exception($message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For debugging reasons we should throw a different exception. Maybe one of https://github.com/ruflin/Elastica/tree/master/lib/Elastica/Exception ? @ruflin ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM. The part I'm worried here is that this could be a breaking change in Elastica? Want to open a PR against Elastica to discuss it there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the exception from the global Exception to ClientException, good point! Gents, thank you both so much for your help and let me know if something more is needed |
||
} | ||
|
||
$responseData = $response->getData(); | ||
if (isset($responseData['took']) && isset($responseData['hits'])) { | ||
$this->logQuery($path, $method, $data, $query, $response->getQueryTime(), $response->getEngineTime(), $responseData['hits']['total']); | ||
} else { | ||
|
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 would like to keep stable packages.
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.
Completely agreed, alas last release from ruflin/elastica is from waaay back
See link for reference https://github.com/ruflin/Elastica/releases
And the commit that's needed for this PR, is a fairly recent one on master
ruflin/Elastica@d6f1475
I'm not sure what's the best way around this? ask ruflin to release a new version?
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.
@jandom Is a new release needed from master?
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.
@ruflin nothing would make me more happy – but i'm not sure what your release cycle is like/don't want to bother if you're waiting for something else to merge in
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.
@ruflin yeah let's have a new ruflin/Elastica release, if that's okay – it'll push this PR forward
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.
Next week is totally appropriate
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.
@ruflin super-gentle nudge if there are any updates on the new release of ruflin/Elastica?
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.
Thanks for the nudge ;-) Just opened the PR to prepare the release. Now I only need a review for it: ruflin/Elastica#1547
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.
@jandom This should help: https://github.com/ruflin/Elastica/releases/tag/6.1.0
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.
Yaaas thank you!