From 2b698e56f5b005226d00533767abdcf18c99e8cb Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 18 Sep 2017 18:01:31 +0200 Subject: [PATCH] Added error arguments to serialized version (json) --- build/api/core/Response.php | 3 ++- build/error/core/Error.php | 44 ++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/build/api/core/Response.php b/build/api/core/Response.php index 840f91b..77f1507 100644 --- a/build/api/core/Response.php +++ b/build/api/core/Response.php @@ -109,7 +109,8 @@ // On rajoute l'erreur au message $returnData = array_merge([ 'error' => $this->error->get(), - 'ErrorDescription' => $this->error->explicit() + 'ErrorDescription' => $this->error->explicit(), + 'ErrorArguments' => $this->error->args() ], $this->data ); diff --git a/build/error/core/Error.php b/build/error/core/Error.php index aee53d5..745cd0c 100644 --- a/build/error/core/Error.php +++ b/build/error/core/Error.php @@ -7,8 +7,8 @@ class Error{ - private $error = null; - private $arguments = []; + private $error = null; + private $args = []; /* ERROR CONSTRUCTOR * @@ -48,7 +48,7 @@ $this->error = !is_numeric($const) ? Err::UnknownError : $const; /* (2) On récupère les arguments */ - $this->arguments = array_slice(func_get_args(), 1); + $this->args = array_slice(func_get_args(), 1); } @@ -98,8 +98,8 @@ private function Success(){ return 'all right'; }private function ParsingFailed(){ - if( count($this->arguments) > 0 ) - return "{$this->arguments[0]} parsing failed"; + if( count($this->args) > 0 ) + return "{$this->args[0]} parsing failed"; else return 'parsing failed'; }private function UnreachableResource(){ @@ -119,23 +119,23 @@ }private function WrongPathModule(){ return 'wrong module\'s path'; }private function UnknownModule(){ - if( count($this->arguments) > 0 ) - return "unknown module '{$this->arguments[0]}'"; + if( count($this->args) > 0 ) + return "unknown module '{$this->args[0]}'"; else return 'unknown module'; }private function UnknownMethod(){ - if( count($this->arguments) > 0 ) - return "unknown method '{$this->arguments[0]}'"; + if( count($this->args) > 0 ) + return "unknown method '{$this->args[0]}'"; else return 'unknown method'; }private function UncallableModule(){ - if( count($this->arguments) > 0 ) - return "uncallable module '{$this->arguments[0]}'"; + if( count($this->args) > 0 ) + return "uncallable module '{$this->args[0]}'"; else return 'uncallable module'; }private function UncallableMethod(){ - if( count($this->arguments) > 0 ) - return "uncallable method '{$this->arguments[0]}'"; + if( count($this->args) > 0 ) + return "uncallable method '{$this->args[0]}'"; else return 'uncallable method'; }private function UnknownHttpMethod(){ @@ -143,16 +143,16 @@ }private function ConfigError(){ return 'configuration error'; }private function MissingParam(){ - if( count($this->arguments) > 0 ) - return "missing param '{$this->arguments[0]}'"; + if( count($this->args) > 0 ) + return "missing param '{$this->args[0]}'"; else return 'missing param'; }private function WrongParam(){ - if( count($this->arguments) > 0 ) - if( count($this->arguments) > 1 ) - return "wrong param '{$this->arguments[0]}' expected to be of type '{$this->arguments[1]}'"; + if( count($this->args) > 0 ) + if( count($this->args) > 1 ) + return "wrong param '{$this->args[0]}' expected to be of type '{$this->args[1]}'"; else - return "wrong param '{$this->arguments[0]}'"; + return "wrong param '{$this->args[0]}'"; else return 'wrong param'; }private function ModuleError(){ @@ -180,15 +180,15 @@ }private function UnknownDebugError(){ return 'unknown debug error'; }private function AlreadyExists(){ - if( count($this->arguments) > 0 ) - return "'{$this->arguments[0]}' already exists"; + if( count($this->args) > 0 ) + return "'{$this->args[0]}' already exists"; return 'entry already exists'; } public function args(){ - return $this->arguments; + return $this->args; }