From 65e3d9da64c86d01c1ae71e99de0ccb9e85107cc Mon Sep 17 00:00:00 2001
From: Antony Le Courtes <antony.lecourtes@unicaen.fr>
Date: Tue, 21 Sep 2021 14:32:47 +0200
Subject: [PATCH] =?UTF-8?q?Gestion=20exception=20si=20ws=20ne=20r=C3=A9pon?=
 =?UTF-8?q?dent=20pas?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/UnicaenSiham/Exception/SihamException.php | 11 ++++++++---
 src/UnicaenSiham/Service/Siham.php            |  3 ++-
 src/UnicaenSiham/Service/SihamClient.php      | 12 +++++++++---
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/UnicaenSiham/Exception/SihamException.php b/src/UnicaenSiham/Exception/SihamException.php
index 785dbe9..78fd5d4 100644
--- a/src/UnicaenSiham/Exception/SihamException.php
+++ b/src/UnicaenSiham/Exception/SihamException.php
@@ -17,6 +17,7 @@ class SihamException extends \Exception
         "AJOUT_IMPOSSIBLE"                       => "Ajout de l'adresse impossible",
         "TYPTEL_DEJA_PRESENT"                    => "Un type de numéro de téléphone existe déjà pour cet agent",
         "LONG_COMPL_ADRESSE_SUPERIEURE_A_38 "    => "La longeur de l'adresse dépasse 38 caractéres",
+        "failed to load external entity"         => "Les webservices SIHAM ne sont pas disponibles pour le moment.",
     ];
 
 
@@ -24,24 +25,28 @@ class SihamException extends \Exception
     public function __construct($message = "", $code = 0, \Throwable $previous = null)
     {
 
-        //Message par défault dans le cas d'une erreur de l'API
-        $defaultMessage = "Un problème est survenu lors de l'appel à l'API SIHAM / " . $message;
         if (!is_null($previous)) {
             $defaultMessage .= " (" . $previous->getMessage() . ")";
         }
 
         $translate = '';
 
+
         foreach ($this->errorMessages as $error => $mess) {
+
             if (preg_match("/$error/", $message)) {
                 $translate = "Un problème est survenu lors de l'appel à l'API SIHAM / " . $mess;
+
+                if ($error == 'failed to load external entity') {
+                    $translate = $mess;
+                }
                 break;
             }
         }
 
         $message = (!empty($translate)) ? $translate : $defaultMessage;
 
-        parent::__construct($message, $code, $previous);
+        return parent::__construct($message, $code, $previous);
     }
 
 
diff --git a/src/UnicaenSiham/Service/Siham.php b/src/UnicaenSiham/Service/Siham.php
index 7b43d7d..f547241 100644
--- a/src/UnicaenSiham/Service/Siham.php
+++ b/src/UnicaenSiham/Service/Siham.php
@@ -772,7 +772,7 @@ class Siham
                 ];
             }
         }
-        
+
         $paramsWS = ['ParamPEC' => [
             'categorieEntree'           => (isset($params['categorieEntree'])) ? strtoupper($params['categorieEntree']) : '',
             'civilite'                  => (isset($params['civilite'])) ? strtoupper($params['civilite']) : '',
@@ -791,6 +791,7 @@ class Siham
             'listeNationalites'         => $listeNationalites,
             'listeNumerosTelephoneFax'  => $listeNumerosTelephoneFax,
             'listePositions'            => $listePositions,
+            'listeCarriere'             => $listeCarriere,
             'listeContrats'             => $listeContrats,
             'motifEntree'               => (isset($params['motifEntree'])) ? strtoupper($params['motifEntree']) : self::SIHAM_MOTIF_ENTREE_DEFAULT,
             'nomPatronymique'           => (isset($params['nomPatronymique'])) ? strtoupper($params['nomPatronymique']) : '',
diff --git a/src/UnicaenSiham/Service/SihamClient.php b/src/UnicaenSiham/Service/SihamClient.php
index 5927a22..7b08260 100644
--- a/src/UnicaenSiham/Service/SihamClient.php
+++ b/src/UnicaenSiham/Service/SihamClient.php
@@ -3,6 +3,8 @@
 namespace UnicaenSiham\Service;
 
 
+use UnicaenSiham\Exception\SihamException;
+
 class SihamClient
 {
     const SOAP_VERSION = SOAP_1_1;
@@ -98,8 +100,12 @@ class SihamClient
 
 
         if (array_key_exists($webserviceName, $this->wsdl)) {
-            $wsdl         = $this->baseUrl . $this->wsdl[$webserviceName];
-            $this->client = new \SoapClient($wsdl, $params);
+            $wsdl = $this->baseUrl . $this->wsdl[$webserviceName];
+            try {
+                $this->client = new \SoapClient($wsdl, $params);
+            } catch (\Exception $e) {
+                throw new SihamException($e->getMessage(), 0, $e);
+            }
         } else {
             throw new \Exception('Le webservice demandé n\'existe pas');
         }
@@ -111,7 +117,7 @@ class SihamClient
 
     public function getLastRequest()
     {
-        
+
         if ($this->client instanceof \SoapClient) {
             return $this->client->__getLastRequest();
         }
-- 
GitLab