Commit 716a6ecd authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Meilleure gestion des exceptions

parent bdb42503
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ class SihamException extends \Exception
        $translateMessage = '';
        $defaultMessage = "Un problème est survenu lors de l'appel à l'API SIHAM / " . $message;

        if (!is_null($previous)) {
        if (!is_null($previous) && $previous->getMessage() !== $message) {
            $defaultMessage .= "(" . $previous->getMessage() . ")";
        }

+100 −131
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ class Siham
    protected $result;



    public function __construct(SihamClient $sihamClient, array $config)
    {
        $this->sihamClient = $sihamClient;
@@ -90,21 +89,18 @@ class Siham
    }



    public function getClient(): SihamClient
    {
        return $this->sihamClient;
    }



    public function getConfig(): array
    {
        return $this->sihamConfig;
    }



    /**
     * Méthode permettant de rechercher une liste d'agent par nom, prénom etc...
     * Possibilité d'utiliser le joker '?' pour faire des recherches
@@ -158,7 +154,6 @@ class Siham
    }



    /**
     * Méthode permettant de récuperer une liste d'agent avec des critères de recherches supplémentaire : nom, prénom, numero INSEE
     * et date d'observation
@@ -234,7 +229,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant de récupérer les données personnelles d'un agent (Adresse, téléphone, email etc...)
@@ -279,7 +273,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant de récupérer les données administrative d'un agent (Affectation, carrière, contrat etc...)
@@ -321,7 +314,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant de modifier ou créer l'adresse principale d'un agent dans SIHAM
@@ -363,7 +355,9 @@ class Siham
                    return true;
                } else {
                    $message = $result->return->statutMAJ;
                    throw new SihamException($result->return->statutMAJ, 0);
                    $exception = new SihamException($result->return->statutMAJ, 0);
                    $this->sendDebug('WS DossierAgentWebService / METHOD ModifDonneesPersonnelles', $exception);
                    throw $exception;
                }
            }
        } catch (\Exception $e) {
@@ -375,7 +369,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant d'historiser (soft delete) l'adresse d'un agent dans SIHAM
@@ -441,7 +434,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant de modifier ou créer un téléphone (pro, perso) ou un email (pro, perso) d'un agent dans SIHAM
@@ -495,7 +487,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant d'historiser (soft delete) un téléphone (pro, perso) ou un email (pro, perso) d'un agent dans SIHAM
@@ -563,7 +554,6 @@ class Siham
    }



    public function modifierCoordonnéesBancairesAgent(array $params): bool
    {
        $paramsWS = ['ParamMCB' => [
@@ -597,7 +587,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant la prise en charge (création d'un agent) dans SIHAM. Retour le matricule de l'agent SIHAM qui vient d'être créé.
@@ -841,10 +830,13 @@ class Siham
        ]];

        try {

            $client = $this->sihamClient->getClient('PECWebService');
            $result = $client->PriseEnChargeAgent($paramsWS);
            $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent');
        } catch (\Exception $e) {
            $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent', $e);
            throw new SihamException($e->getMessage(), 0, $e);
        }

        if ($result->return->statut == 'ERREUR_GENERALE') {
            $messageErreur = '';
@@ -867,24 +859,22 @@ class Siham
                }
            }
            //Traitement du message d'erreur spécifique à la PEC
                $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent');
                throw new SihamException($messageErreur, 0);
            $exception = new SihamException($messageErreur, 0);
            $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent', $exception);
            throw $exception;
        } elseif ($result->return->statut == 'MAJ OK' && !empty($result->return->matricule)) {
            return $result->return->matricule;
        } else {
                $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent');
                throw new SihamException('Erreur non identifié, veuillez vous rapprocher du support informatique', 0);
            }
        } catch (\Exception $e) {
            $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent', $e);
            throw new SihamException($e->getMessage(), 0, $e);
            $exception = new SihamException('Erreur non identifié, veuillez vous rapprocher du support informatique', 0);
            $this->sendDebug('WS PECWebService / METHOD PriseEnChargeAgent', $exception);
            throw $exception;
        }


        return null;
    }



    /**
     *
     * Méthode permettant le renouvellement d'un agent existant dans SIHAM. Retour le matricule de l'agent SIHAM qui vient d'être créé.
@@ -987,13 +977,14 @@ class Siham

        ]];


        try {

            $client = $this->sihamClient->getClient('PECWebService');
            $result = $client->RenouvellementAgent($paramsWS);
            $this->sendDebug('WS PECWebService / METHOD RenouvellementAgent');

        } catch (\Exception $e) {
            $this->sendDebug('WS PECWebService / METHOD RenouvellementAgent', $e);
            throw new SihamException($e->getMessage(), 0, $e);
        }
        if ($result->return->statut == 'ERREUR_GENERALE') {
            $messageErreur = '';
            $messageWarning = '';
@@ -1015,23 +1006,20 @@ class Siham
                }
            }

                throw new SihamException($messageErreur, 0);
            $exception = new SihamException($messageErreur, 0);
            $this->sendDebug('WS PECWebService / METHOD RenouvellementAgent', $exception);
            throw $exception;
        } elseif ($result->return->statut == 'MAJ OK' && !empty($result->return->matricule)) {
            return $result->return->matricule;
        } else {

                throw new SihamException('Erreur non identifié, veuillez vous rapprocher du support informatique', 0);
            $exception = new SihamException('Erreur non identifié, veuillez vous rapprocher du support informatique', 0);
            $this->sendDebug('WS PECWebService / METHOD RenouvellementAgent', $exception);
            throw $exception;
        }
        } catch (\SoapFault $e) {
            $this->sendDebug('WS PECWebService / METHOD RenouvellementAgent', $e);
            throw new SihamException($e->getMessage(), 0, $e);
        }

        return null;
    }



    public function cloreDossier(array $params): bool
    {

@@ -1056,7 +1044,6 @@ class Siham
    }



    /**
     *
     * Méthode permettant de récupérer les valeurs d'une nomenclature (code répertoire) de SIHAM
@@ -1103,7 +1090,6 @@ class Siham
    }



    public function recupererListeStatuts($from = '')
    {
        if (!empty($this->sihamConfig['filters'][$this->codeNomenclatureStatuts])) {
@@ -1118,7 +1104,6 @@ class Siham
    }



    public function recupererListeGrades($from = '')
    {
        $params = [
@@ -1131,7 +1116,6 @@ class Siham
    }



    public function recupererListeModalites($from = '')
    {
        if (!empty($this->sihamConfig['filters'][$this->codeNomenclatureModalites])) {
@@ -1148,7 +1132,6 @@ class Siham
    }



    public function recupererListePositions($from = '')
    {
        if (!empty($this->sihamConfig['filters'][$this->codeNomenclaturePositions])) {
@@ -1165,7 +1148,6 @@ class Siham
    }



    public function recupererListeEmplois()
    {
        if (!empty($this->sihamConfig['filters']['emplois'])) {
@@ -1176,7 +1158,6 @@ class Siham
    }



    public function recupererListeCorps($from = '')
    {
        $params = [
@@ -1189,7 +1170,6 @@ class Siham
    }



    public function recupererListeSectionsCnu($from = '')
    {
        $params = [
@@ -1202,7 +1182,6 @@ class Siham
    }



    public function recupererListeContrats($from = '')
    {
        $params = [
@@ -1215,7 +1194,6 @@ class Siham
    }



    public function recupererListeFamillesProfessionnelles($from = '')
    {
        $params = [
@@ -1228,7 +1206,6 @@ class Siham
    }



    public function recupererListeCategories($from = '')
    {
        $params = [
@@ -1241,7 +1218,6 @@ class Siham
    }



    public function recupererListeEchelons($from = '')
    {
        $params = [
@@ -1254,7 +1230,6 @@ class Siham
    }



    public function recupererListeAdminsitrations($from = '')
    {
        $params = [
@@ -1267,7 +1242,6 @@ class Siham
    }



    public function recupererListeEtablissements($from = '')
    {
        $params = [
@@ -1280,7 +1254,6 @@ class Siham
    }



    public function recupererListeUO(array $params)
    {
        //Traitement des listes unité organisationnelle
@@ -1348,7 +1321,6 @@ class Siham
    }



    public function formatCoordoonneesBancairesForSiham($iban, $bic)
    {
        //On récupére l'iban et on doit le décompser pour récupérer les informations nécessaire à SIHAM
@@ -1367,21 +1339,18 @@ class Siham
    }



    public function getCodeEtablissement()
    {
        return $this->codeEtablissement;
    }



    public function getCodeAdministration()
    {
        return $this->codeAdministration;
    }



    public function sendDebug($message = '', $exception = null)
    {
        $config = $this->sihamConfig;