Server error :Reserved for implementation-defined server-errors. const E_PARSE_ERROR = "-32700"; const E_INVALID_REQUEST = "-32600"; const E_METHOD_NOT_FOUND = "-32601"; const E_INVALID_PARAMS = "-32602"; const E_INTERNAL_ERROR = "-32603"; const E_HTTP_NOT_FOUND = "404"; const E_UNKNOWN_ERROR = "500"; // Errors inherited from Expresso Application. const LOGIN_SUCCESS_LOGOUT = "1"; const LOGIN_SESSION_EXPIRED = "2"; const LOGIN_NOT_LOGGED_IN = "3"; const LOGIN_COOKIES_REQUIRED = "4"; const LOGIN_BADLOGIN = "5"; const LOGIN_PASSWORD_EXPIRED = "6"; const LOGIN_AUTH_INVALID = "7"; const LOGIN_SESSION_NOT_VERIFIED = "10"; const LOGIN_ACCOUNT_EXPIRED = "98"; const LOGIN_LOGIN_BLOCKED = "99"; const LOGIN_INVALID_LOGIN = "200"; const CATALOG_MIN_ARGUMENT_SEARCH = "1001"; const MAIL_NOT_SENT = "1002"; const MAIL_TRASH_NOT_CLEANED = "1003"; static private $reservedErrors = array ( self::E_PARSE_ERROR => "Parse error", self::E_INVALID_REQUEST => "Invalid Request", self::E_METHOD_NOT_FOUND => "Method not found", self::E_INVALID_PARAMS => "Invalid params", self::E_INTERNAL_ERROR => "Internal error", self::E_HTTP_NOT_FOUND => 'A resource matching URI "%1" was not found', self::E_UNKNOWN_ERROR => "HTTP Unknown error" ); // Errors inherited from Expresso Application. static private $applicationErrors = array( self::LOGIN_SUCCESS_LOGOUT => "You have been successfully logged out", self::LOGIN_SESSION_EXPIRED => "Sorry, your login has expired", self::LOGIN_NOT_LOGGED_IN => "You are not logged in", self::LOGIN_COOKIES_REQUIRED => "Cookies are required to login to this site.", self::LOGIN_BADLOGIN => "bad login or password", self::LOGIN_PASSWORD_EXPIRED => "Your password has expired, and you do not have access to change it", self::LOGIN_AUTH_INVALID => "Your auth is invalid", self::LOGIN_SESSION_NOT_VERIFIED => "Your session could not be verified.", self::LOGIN_ACCOUNT_EXPIRED => "Account is expired", self::LOGIN_LOGIN_BLOCKED => "Blocked, too many attempts!", self::LOGIN_INVALID_LOGIN => "Bad login or password", self::CATALOG_MIN_ARGUMENT_SEARCH => "Your search argument must be longer than %1 characters.", self::MAIL_NOT_SENT => "Your mail could not be sent.", self::MAIL_TRASH_NOT_CLEANED => "Your trash folder could not be cleaned." ); static public function set($code, $message){ return array ("code" => $code, "message" => $message); } static public function get($code, $argument = false){ $errors = self::$reservedErrors + self::$applicationErrors; $message = $errors[$code]; if(!$message) $message = $errors[self::E_UNKNOWN_ERROR]; if($argument) $message = str_replace("%1", $argument, $message); return array ("code" => $code, "message" => $message); } static public function getResponse($request, $responseException){ $response = new Response($request); $response->code = Response::OK; $response->addHeader('content-type', 'application/json'); if($request->id) $body['id'] = $request->id; $code = $responseException->getCode(); $error = Errors::get($code); $message = ($responseException->getMessage() ? $responseException->getMessage() : $error['message']); $body['error'] = array("code" => $code, "message" => $message); $response->body = json_encode($body); return $response; } }