[phonenumber validation & format] format and validation does not make the app fail when network is not available

This commit is contained in:
Julien Fastré 2020-03-10 09:48:59 +01:00
parent e348616d00
commit 7a952d6f88
3 changed files with 19 additions and 2 deletions

View File

@ -104,4 +104,4 @@ Branch CRUD-Init
- module `show_hide`: add the possibility to launch a show hide manually and not on page loading. Useful when show/hide occurs in collection.
- module `show_hide`: add events to module
- [phonenumber validation] allow to validate against mobile **or** landline/voip phonenumbers;
- [phonenumber validation & format] format and validation does not make the app fail when network is not available;

View File

@ -20,6 +20,7 @@ namespace Chill\MainBundle\Phonenumber;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Exception\ConnectException;
use Psr\Log\LoggerInterface;
use Psr\Cache\CacheItemPoolInterface;
@ -182,6 +183,14 @@ class PhonenumberHelper
"phonenumber" => $phonenumber
]);
return null;
} catch (ConnectException $e) {
$this->logger->error("[phonenumber helper] Could not format number "
. "due to connect error", [
"message" => $e->getMessage(),
"phonenumber" => $phonenumber
]);
return null;
}
@ -230,6 +239,14 @@ class PhonenumberHelper
"phonenumber" => $phonenumber
]);
return null;
} catch (ConnectException $e) {
$this->logger->error("[phonenumber helper] Could not format number "
. "due to connect error", [
"message" => $e->getMessage(),
"phonenumber" => $phonenumber
]);
return null;
}

View File

@ -47,6 +47,6 @@ class Templating extends AbstractExtension
public function formatPhonenumber($phonenumber)
{
return $this->phonenumberHelper->format($phonenumber);
return $this->phonenumberHelper->format($phonenumber) ?? $phonenumber;
}
}