From f15ca028596a9226fcff636138533a1a39f39ce5 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Mon, 31 Mar 2014 11:59:37 +0200 Subject: [PATCH 1/2] Fix documentation for client overwriting. --- .../doc/cookbook/suppress-server-errors.md | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Resources/doc/cookbook/suppress-server-errors.md b/Resources/doc/cookbook/suppress-server-errors.md index aa74276..d89ffd6 100644 --- a/Resources/doc/cookbook/suppress-server-errors.md +++ b/Resources/doc/cookbook/suppress-server-errors.md @@ -1,5 +1,5 @@ Suppressing Server Errors -======================== +========================= By default, exceptions from the Elastica client library will propagate through the bundle's Client class. For instance, if the Elasticsearch server is offline, @@ -12,25 +12,44 @@ container parameter with a custom class. In the following example, we override the `Client::request()` method and return the equivalent of an empty search response if an exception occurred. -``` +Sample client code: +------------------- + +```php + + + + + Acme\ElasticaBundle\Client + + + From 3addfffc916f4ed09d774537a4f77728e6fd1ddb Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 23 May 2014 22:57:57 +1000 Subject: [PATCH 2/2] Added logging of server errors to example --- .../doc/cookbook/suppress-server-errors.md | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Resources/doc/cookbook/suppress-server-errors.md b/Resources/doc/cookbook/suppress-server-errors.md index d89ffd6..e4e371e 100644 --- a/Resources/doc/cookbook/suppress-server-errors.md +++ b/Resources/doc/cookbook/suppress-server-errors.md @@ -32,6 +32,16 @@ class Client extends BaseClient try { return parent::request($path, $method, $data, $query); } catch (ExceptionInterface $e) { + if ($this->_logger) { + $this->_logger->warning('Failed to send a request to ElasticSearch', array( + 'exception' => $e->getMessage(), + 'path' => $path, + 'method' => $method, + 'data' => $data, + 'query' => $query + )); + } + return new Response('{"took":0,"timed_out":false,"hits":{"total":0,"max_score":0,"hits":[]}}'); } } @@ -41,15 +51,9 @@ class Client extends BaseClient Configuration change: --------------------- -```xml - +You must update a parameter in your `app/config/config.yml` file to point to your overridden client: - - - - Acme\ElasticaBundle\Client - - - +```yaml +parameters: + fos_elastica.client.class: Acme\ElasticaBundle\Client +```