istic-openstack/server/core/ErrorManagement.php

128 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2016-02-12 12:45:00 +01:00
<?php
2016-03-27 19:40:36 +02:00
/**
2016-04-27 14:22:59 +02:00
* File containing the errorManagement Class.
2016-03-27 19:40:36 +02:00
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Eole 'eoledev at outlook . fr', Evan Pisani 'yogg at epsina . com'
*
*/
2016-02-12 12:45:00 +01:00
2016-03-09 15:21:46 +01:00
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
2016-02-12 12:45:00 +01:00
2016-04-27 14:22:59 +02:00
/**
* errorManagement Class of the back-end application
*
* Management of error
*
*/
2016-02-12 12:45:00 +01:00
Class errorManagement{
2016-04-27 14:22:59 +02:00
2016-03-27 19:40:36 +02:00
/** @var App $app protected, contains the main app object */
2016-02-12 12:45:00 +01:00
protected $app;
2016-03-27 19:40:36 +02:00
/**
* ErrorManagemement constructor
*
2016-04-26 20:42:31 +02:00
* @param App $args the main app object
2016-03-27 19:40:36 +02:00
*
2016-04-26 20:42:31 +02:00
* @return ErrorManagement Object
2016-03-27 19:40:36 +02:00
*/
2016-02-12 12:45:00 +01:00
public function __construct($args){
$this->app = $args;
}
2016-03-27 19:40:36 +02:00
/**
* Put an error message corresponding to a base error in the output
*
2016-04-26 20:42:31 +02:00
* @param Exception $error the exception triggered
2016-03-27 19:40:36 +02:00
*
2016-04-27 14:22:59 +02:00
* @return void
2016-03-27 19:40:36 +02:00
*/
2016-02-12 12:45:00 +01:00
public function BaseErrorHandler($error){
$this->app->setOutput("Error", "BaseError");
2016-02-12 12:45:00 +01:00
}
2016-03-27 19:40:36 +02:00
/**
* Put an error message corresponding to a bad response in function of the status code in the output
*
2016-04-26 20:42:31 +02:00
* @param Exception $error the exception triggered
2016-03-27 19:40:36 +02:00
*
2016-04-27 14:22:59 +02:00
* @return void
2016-03-27 19:40:36 +02:00
*/
2016-02-12 12:45:00 +01:00
public function BadResponseHandler($error){
$statusCode = $error->getResponse()->getStatusCode();
switch ($statusCode) {
2016-04-26 20:42:31 +02:00
case 400:
$this->app->setOutput("Error", "Invalid input.");
break;
2016-04-26 20:42:31 +02:00
case 401:
$this->app->setOutput("Error", "Authentification failed.");
break;
2016-04-26 20:42:31 +02:00
case 403:
$this->app->setOutput("Error", "Operation forbidden.");
break;
2016-04-26 20:42:31 +02:00
case 404:
$this->app->setOutput("Error", "Ressource not found.");
break;
2016-04-26 20:42:31 +02:00
case 500:
$this->app->setOutput("Error", "Internal server error, please contact an administrator.");
break;
2016-04-26 20:42:31 +02:00
case 503:
$this->app->setOutput("Error", "Service unvailable for the moment.");
break;
2016-04-26 20:42:31 +02:00
default:
$this->app->setOutput("Error", "Unknow error, please contact an administrator.");
break;
}
2016-02-12 12:45:00 +01:00
}
2016-03-27 19:40:36 +02:00
/**
* Put an error message corresponding to a not implemented yet error in the output
*
2016-04-26 20:42:31 +02:00
* @param Exception $error the exception triggered
2016-03-27 19:40:36 +02:00
*
2016-04-27 14:22:59 +02:00
* @return void
2016-03-27 19:40:36 +02:00
*/
2016-02-12 12:45:00 +01:00
public function NotImplementedHandler($error){
$this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator");
2016-02-12 12:45:00 +01:00
}
2016-03-27 19:40:36 +02:00
/**
* Put an error message corresponding to a user input error in the output
*
2016-04-26 20:42:31 +02:00
* @param Exception $error the exception triggered
2016-03-27 19:40:36 +02:00
*
2016-04-27 14:22:59 +02:00
* @return void
2016-03-27 19:40:36 +02:00
*/
2016-02-12 12:45:00 +01:00
public function UserInputHandler($error){
$this->app->setOutput("Error", "UserInputError");
2016-02-12 12:45:00 +01:00
}
2016-03-27 19:40:36 +02:00
/**
* Put an error message corresponding to an other error in the output
*
2016-04-26 20:42:31 +02:00
* @param Exception $error the exception triggered
2016-03-27 19:40:36 +02:00
*
2016-04-27 14:22:59 +02:00
* @return void
2016-03-27 19:40:36 +02:00
*/
public function OtherException($error){
2016-03-21 10:19:26 +01:00
$this->app->setOutput("Error", $error->getMessage());
}
2016-02-12 12:45:00 +01:00
}
2016-03-09 15:21:46 +01:00
?>