summaryrefslogtreecommitdiff
path: root/server/core
diff options
context:
space:
mode:
authorYoggzo <yogg@epsina.com>2016-03-27 19:24:03 +0200
committerYoggzo <yogg@epsina.com>2016-03-27 19:24:03 +0200
commite9c7477ff0acedf9b49e508e1543395bbcbf7533 (patch)
treee3236417f9bb7f828de4b49d6ceb45e3986131d9 /server/core
parentdcf0d8b2ba2547720215f7de55a747bf7ec47a0b (diff)
Modifications in error management and correct error in Image.php
Diffstat (limited to 'server/core')
-rwxr-xr-xserver/core/App.php15
-rwxr-xr-xserver/core/ErrorManagement.php37
-rwxr-xr-xserver/core/Image.php8
3 files changed, 47 insertions, 13 deletions
diff --git a/server/core/App.php b/server/core/App.php
index 10813bd..48bb9ab 100755
--- a/server/core/App.php
+++ b/server/core/App.php
@@ -112,15 +112,20 @@ class App{
}
public function getPostParam($name){
-
- return $this->postParams[$name];
+
+ if(isset($this->postParams[$name])){
+ return $this->postParams[$name];
+ }else{
+ $this->setOutput("Error", "Missing parameter ".$name);
+ }
}
- public function setPostParam($name, $value){
-
- $this->postParams[$name]= $value;
+
+ public function setPostParam($param, $value){
+ $this->postParams[$param] = $value;
+
}
public function setOutput($key, $out){
diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php
index 3257dd3..e7cb83e 100755
--- a/server/core/ErrorManagement.php
+++ b/server/core/ErrorManagement.php
@@ -18,19 +18,48 @@ Class errorManagement{
}
public function BaseErrorHandler($error){
-
+ $this->app->setOutput("Error", "BaseError");
}
public function BadResponseHandler($error){
- $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
+ $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;
+ }
}
public function NotImplementedHandler($error){
- $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
+ $this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator");
}
public function UserInputHandler($error){
-
+ $this->app->setOutput("Error", "UserInputError");
}
public function OtherException($error){
diff --git a/server/core/Image.php b/server/core/Image.php
index 71e19ce..e9736a2 100755
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -76,7 +76,7 @@ class image implements Core{
// Check the image name
if(isset($opt['name'])){
- $imagesList = listImage();
+ $imagesList = $this->listImage();
if(isset($imagesList)){
foreach($imagesList as $image){
if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error
@@ -84,7 +84,7 @@ class image implements Core{
}
}
}
-
+ $options['name'] = $opt['name'];
}
else{
$this->app->setOutput("Error", "Missing parameter 'name' for the new image");
@@ -118,7 +118,7 @@ class image implements Core{
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'];
}
- if(isset($opt['properties'])){ // type dict ?
+ if(isset($opt['properties'])){ // type dict
$options['properties'] = $opt['properties'];
}
@@ -187,7 +187,6 @@ class image implements Core{
$this->app->setOutput("Error", "Image doesn't exist");
}
else{
- echo 'toto';
$this->app->setOutput("Images", $image);
}
}catch(BadResponseError $e){
@@ -326,6 +325,7 @@ class image implements Core{
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
+
$image->reactivate();
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);