Files
PVM/public_html/classes/ErrorHandler.class.php
ClaudioR c9f79a055b [Contratti di Acquisto]
- Corretto l'invio ed il carico allegati (tutti al listino)
- Completato la stampa
- Bug fixes e correzioni
2022-02-07 15:46:58 +01:00

172 lines
7.7 KiB
PHP

<?php
class ErrorHandler {
const EMSCONNECT = 0;
const EMSHTTP = 1;
const EMSHTTP400 = 2;
const EMSPARSE = 3;
const EMSNOMESSAGE = 4;
const UNEXPECTED_AJAX_METHOD = 5;
const MISSING_SETUP = 6;
const INVALID_REPORT = 7;
const NORESULT_REPORT = 8;
const UNAUTHORIZED_USER = 9;
const FAIL_IMAGERESIZE = 10;
const UNEXPECTED_METHOD = 11;
// apixu (deprecated)
const APIXU_MISSING_INVALID_KEY = 1002;
const APIXU_MISSING_Q = 1003;
const APIXU_INVALID_URL = 1005;
const APIXU_LOCATION_NOT_FOUND = 1006;
const APIXU_DAY_UNAVAILABLE = 1008;
const APIXU_INVALID_KEY = 2006;
const APIXU_EXCEED_QUOTA = 2007;
const APIXU_DISABLED_KEY = 2008;
const APIXU_INTERNAL_ERROR = 9999;
// reCAPTCHA
const MISSINGINPUTSECRET = "missing-input-secret";
const INVALIDINPUTSECRET = "invalid-input-secret";
const MISSINGINPUTRESPONSE = "missing-input-response";
const INVALIDINPUTRESPONSE = "invalid-input-response";
const BADREQUEST = "bad-request";
public static function get_message($errorCode, $p1 = null, $p2 = null, $p3 = null) {
// sostituito switch/case con if/elseif perche non veniva cfatta la comparazione col tipo
if ($errorCode === self::EMSCONNECT) {
return (!is_null($p1) ? "<span class='text-monospace'>Servizio <b>{$p1}</b></span><hr class='mt-0 mb-10'/>" : "")
. "Il servizio EMS non &egrave; raggiungibile";
} else if ($errorCode === self::EMSHTTP) {
return (!is_null($p1) ? "<span class='text-monospace'>Servizio <b>{$p3}</b></span><hr class='mt-0 mb-10'/>" : "")
. "La chiamata al servizio ha restituito l'errore http <u>" . blankIfNull($p1) . "</u>" . (!is_null($p2) ? "<div class='mt-10 text-muted text-monospace small'>{$p2}</div>" : "");
} else if ($errorCode === self::EMSHTTP400) {
return (!is_null($p1) ? "<span class='text-monospace'>Servizio <b>{$p1}</b></span><hr class='mt-0 mb-10'/>" : "")
. "La chiamata al servizio ha restituito l'errore http <u>400</u> (Bad Request)";
} else if ($errorCode === self::EMSPARSE) {
return (!is_null($p1) ? "<span class='text-monospace'>Servizio <b>{$p1}</b></span><hr class='mt-0 mb-10'/>" : "") .
"Parse della risposta del servizio <b>" . blankIfNull($p1) . "</b> fallita";
} else if ($errorCode === self::EMSNOMESSAGE) {
return (!is_null($p1) ? "<span class='text-monospace'>Servizio <b>{$p1}</b></span><hr class='mt-0 mb-10'/>" : "")
. "Messaggio di errore non pervenuto";
} else if ($errorCode === self::MISSINGINPUTSECRET) {
return "Parametro secret mancante";
} else if ($errorCode === self::INVALIDINPUTSECRET) {
return "Parametro secret mancante o non valido";
} else if ($errorCode === self::MISSINGINPUTRESPONSE) {
return "Parametro response mancante";
} else if ($errorCode === self::INVALIDINPUTRESPONSE) {
return "Parametro response mancante o non valido";
} else if ($errorCode === self::BADREQUEST) {
return "La richiesta non è valida";
} else if ($errorCode === self::UNEXPECTED_AJAX_METHOD) {
$body = $_SERVER["REQUEST_METHOD"] === "POST" ? $_POST : $_GET;
unset($body["_"]);
$method = count($body) > 0 ? "<i>" . implode(", ", array_keys($body)) . "</i>" : "ajax";
return "Il metodo richiesto {$method} non è previsto";
} else if ($errorCode === self::MISSING_SETUP) {
$message = self::getGestSetupMissingInfo($p1);
if (!is_null($message)) {
return $message;
} else if (!is_null($p1) && is_string($p1)) {
return "Il parametro <i>{$p1}</i> non è stato configurato";
} else {
return "Un parametro del modulo corrente non è stato configurato";
}
} else if ($errorCode === self::INVALID_REPORT) {
$message = self::getGestSetupMissingInfo($p1);
if (!is_null($message)) {
return "Il report non risulta esser stato configurato:<br/>" . $message;
} else {
return "Il report " . ((!is_null($p1) && is_string($p1)) ? "<i>{$p1}</i>" : "") . "non è valido";
}
} else if ($errorCode === self::NORESULT_REPORT) {
return "Il report non ha generato alcun risultato";
} else if ($errorCode === self::UNAUTHORIZED_USER) {
return "La procedura non è abilitata all'utente";
} else if ($errorCode === self::FAIL_IMAGERESIZE) {
return "Ridimensionamento immagine fallito";
} else if ($errorCode === self::APIXU_MISSING_INVALID_KEY) {
return "La chiave API non è valida o non è stata specificata";
} else if ($errorCode === self::APIXU_MISSING_Q) {
return "Il parametro q non è stato specificato";
} else if ($errorCode === self::APIXU_INVALID_URL) {
return "L'url della richiesta non è valido";
} else if ($errorCode === self::APIXU_LOCATION_NOT_FOUND) {
return "Luogo non trovato";
} else if ($errorCode === self::APIXU_DAY_UNAVAILABLE) {
return "Il meteo non è disponibile alla data selezionata";
} else if ($errorCode === self::APIXU_INVALID_KEY) {
return "La chiave API non è valida";
} else if ($errorCode === self::APIXU_EXCEED_QUOTA) {
return "La chiave API ha superato il numero massimo di richieste consentite";
} else if ($errorCode === self::APIXU_DISABLED_KEY) {
return "La chiave API non è abilitata";
} else if ($errorCode === self::APIXU_INTERNAL_ERROR) {
return "Si è verificato un errore di applicazione interno";
} else {
return "Si è verificato un errore non codificato";
}
return null;
}
private static function getGestSetupMissingInfo($GestSetup) {
if (\GestSetup::isGestSetupObject($GestSetup)) {
$description = $GestSetup->getDescription();
$message = "<span class='small font-italic text-uppercase'>" . $GestSetup->getGestName() . " > " . $GestSetup->getSection() . " > <b>" . $GestSetup->getKeySection() . "</b></span>";
if (!is_null($description)) {
$message .= " <span class='text-xs opacity-90 font-italic'>(" . ucfirst($description) . ")</span>";
}
return $message;
}
return null;
}
public static function get_title($errorCode, $p1 = null, $p2 = null, $p3 = null) {
if (in_array($errorCode, array(self::EMSHTTP400, self::EMSHTTP, self::EMSPARSE, self::EMSNOMESSAGE, self::EMSCONNECT))) {
return "Servizio non disponibile";
} else if (in_array($errorCode, array(self::UNEXPECTED_AJAX_METHOD, self::UNEXPECTED_METHOD))) {
return "Operazione non valida";
} else if (in_array($errorCode, array(self::MISSING_SETUP))) {
return "Configurazione setup incompleta";
} else if (in_array($errorCode, array(self::INVALID_REPORT))) {
return "Report non configurato";
} else if (in_array($errorCode, array(self::NORESULT_REPORT))) {
return "Report non generato";
} else if (in_array($errorCode, array(self::UNAUTHORIZED_USER))) {
return "Utente non autorizzato";
} else if (in_array($errorCode, array(self::APIXU_MISSING_INVALID_KEY, self::APIXU_MISSING_Q, self::APIXU_INVALID_URL, self::APIXU_LOCATION_NOT_FOUND, self::APIXU_DAY_UNAVAILABLE, self::APIXU_INVALID_KEY, self::APIXU_EXCEED_QUOTA, self::APIXU_DISABLED_KEY, self::APIXU_INTERNAL_ERROR))) {
return "Servizio meteo non disponibile";
}
return null;
}
}