1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
/**
* File containing the errorManagement Class.
*
* @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'
*
*/
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
/**
* errorManagement Class of the back-end application
*
* Management of error
*
*/
Class errorManagement{
/** @var App $app protected, contains the main app object */
protected $app;
/**
* ErrorManagemement constructor
*
* @param App $args the main app object
*
* @return ErrorManagement Object
*/
public function __construct($args){
$this->app = $args;
}
/**
* Put an error message corresponding to a base error in the output
*
* @param Exception $error the exception triggered
*
* @return void
*/
public function BaseErrorHandler($error){
$this->app->setOutput("Error", "BaseError");
}
/**
* Put an error message corresponding to a bad response in function of the status code in the output
*
* @param Exception $error the exception triggered
*
* @return void
*/
public function BadResponseHandler($error){
$statusCode = $error->getResponse()->getStatusCode();
switch ($statusCode) {
case 400:
$this->app->setOutput("Error", "Invalid input.");
break;
case 401:
$this->app->setOutput("Error", "Authentification failed.");
break;
case 403:
$this->app->setOutput("Error", "Operation forbidden.");
break;
case 404:
$this->app->setOutput("Error", "Ressource not found.");
break;
case 500:
$this->app->setOutput("Error", "Internal server error, please contact an administrator.");
break;
case 503:
$this->app->setOutput("Error", "Service unvailable for the moment.");
break;
default:
$this->app->setOutput("Error", "Unknow error, please contact an administrator.");
break;
}
}
/**
* Put an error message corresponding to a not implemented yet error in the output
*
* @param Exception $error the exception triggered
*
* @return void
*/
public function NotImplementedHandler($error){
$this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator");
}
/**
* Put an error message corresponding to a user input error in the output
*
* @param Exception $error the exception triggered
*
* @return void
*/
public function UserInputHandler($error){
$this->app->setOutput("Error", "UserInputError");
}
/**
* Put an error message corresponding to an other error in the output
*
* @param Exception $error the exception triggered
*
* @return void
*/
public function OtherException($error){
$this->app->setOutput("Error", $error->getMessage());
}
}
?>
|