-
Notifications
You must be signed in to change notification settings - Fork 973
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
Show generic error messages when server returns no response #1055
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
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.
I like the idea of using a default unknown message but I would like to refactor a little bit the PR. Please, have a look at the specific comments. Thanks!
//Provide a generic error message when the server returns no response | ||
$exception = new BadRequest400Exception("Unknown {$statusCode} error from elasticsearch server", $statusCode); | ||
} elseif ($statusCode === 403) { | ||
$responseBody = "Unknown {$statusCode} error from elasticsearch server " . $exception->getMessage(); |
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.
I think we can move that part into a private
function in order to convert $responseBody
into a string, using the "Unknown message" as you proposed in case of empty (or null) value. I'm thinking to something like this:
private function convertBodyToString(
$body,
int $statusCode,
ElasticsearchException $exception
) : string {
if (empty($body)) {
return sprintf(
"Unknown %d error from Elasticsearch %s",
$statusCode,
$exception->getMessage()
);
}
// if body is not string, we convert it so it can be used as Exception message
if (!is_string($body)) {
return json_encode($body);
}
return $body;
}
We should apply this in process4xxError
and process5xxError
as well.
@mlambley can you apply this refactor and send the PR against 7.x
branch? Thanks!
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.
I remade the PR for 7.x
Please see #1056
Closed in favour of #1056 |
Although I just noticed you might want me to target an earlier branch.
6.x
perhaps? Let me know if you wish me to remake this PR.