source: sandbox/webservice/api/rest/core/Errors.php @ 6091

Revision 6091, 3.5 KB checked in by asaikawa, 12 years ago (diff)

Ticket #2507 - Adicionado recurso de limpar a pasta lixeira

Line 
1<?php
2
3final class Errors {
4               
5        // Errors from -32000 to -32099 => Server error :Reserved for implementation-defined server-errors.
6        const E_PARSE_ERROR             = "-32700";     
7        const E_INVALID_REQUEST         = "-32600";
8        const E_METHOD_NOT_FOUND        = "-32601";
9        const E_INVALID_PARAMS          = "-32602";
10        const E_INTERNAL_ERROR          = "-32603";     
11
12        const E_HTTP_NOT_FOUND          = "404";
13        const E_UNKNOWN_ERROR           = "500";
14       
15       
16        // Errors inherited from Expresso Application. 
17        const LOGIN_SUCCESS_LOGOUT                      = "1";
18        const LOGIN_SESSION_EXPIRED             = "2";
19        const LOGIN_NOT_LOGGED_IN                       = "3";
20        const LOGIN_COOKIES_REQUIRED            = "4";
21        const LOGIN_BADLOGIN                            = "5";
22        const LOGIN_PASSWORD_EXPIRED            = "6";
23        const LOGIN_AUTH_INVALID                        = "7";
24        const LOGIN_SESSION_NOT_VERIFIED        = "10";
25        const LOGIN_ACCOUNT_EXPIRED             = "98";
26        const LOGIN_LOGIN_BLOCKED                       = "99";
27        const LOGIN_INVALID_LOGIN                       = "200";
28       
29
30        const CATALOG_MIN_ARGUMENT_SEARCH       = "1001";       
31        const MAIL_NOT_SENT                                     = "1002";
32        const MAIL_TRASH_NOT_CLEANED            = "1003";
33       
34        static private $reservedErrors = array (                       
35                self::E_PARSE_ERROR             => "Parse error",
36                self::E_INVALID_REQUEST         => "Invalid Request",
37                self::E_METHOD_NOT_FOUND        => "Method not found",
38                self::E_INVALID_PARAMS          => "Invalid params",
39                self::E_INTERNAL_ERROR          => "Internal error",
40                self::E_HTTP_NOT_FOUND          => 'A resource matching URI "%1" was not found',
41                self::E_UNKNOWN_ERROR           => "HTTP Unknown error"
42        );
43       
44       
45        // Errors inherited from Expresso Application.
46        static private $applicationErrors = array(                     
47
48                self::LOGIN_SUCCESS_LOGOUT                      => "You have been successfully logged out",
49                self::LOGIN_SESSION_EXPIRED             => "Sorry, your login has expired",
50                self::LOGIN_NOT_LOGGED_IN                       => "You are not logged in",
51                self::LOGIN_COOKIES_REQUIRED            => "Cookies are required to login to this site.",
52                self::LOGIN_BADLOGIN                            => "bad login or password",
53                self::LOGIN_PASSWORD_EXPIRED            => "Your password has expired, and you do not have access to change it",
54                self::LOGIN_AUTH_INVALID                        => "Your auth is invalid",
55                self::LOGIN_SESSION_NOT_VERIFIED        => "Your session could not be verified.",
56                self::LOGIN_ACCOUNT_EXPIRED             => "Account is expired",
57                self::LOGIN_LOGIN_BLOCKED                       => "Blocked, too many attempts!",
58                self::LOGIN_INVALID_LOGIN                       => "Bad login or password",
59                self::CATALOG_MIN_ARGUMENT_SEARCH       => "Your search argument must be longer than %1 characters.",
60                self::MAIL_NOT_SENT                                     => "Your mail could not be sent.",
61                self::MAIL_TRASH_NOT_CLEANED            => "Your trash folder could not be cleaned."
62        );
63               
64        static public function set($code, $message){
65                return array ("code" => $code, "message" => $message);
66        }
67
68        static public function get($code, $argument = false){
69                $errors = self::$reservedErrors + self::$applicationErrors;             
70                $message = $errors[$code];
71                if(!$message)
72                        $message = $errors[self::E_UNKNOWN_ERROR];
73                if($argument)
74                        $message = str_replace("%1", $argument, $message);             
75               
76                return array ("code" => $code, "message" => $message);
77        }
78       
79        static public function getResponse($request, $responseException){                       
80                        $response = new Response($request);
81                        $response->code = Response::OK;
82                        $response->addHeader('content-type', 'application/json');
83                        if($request->id)
84                                $body['id']     = $request->id;
85                       
86                        $code    = $responseException->getCode();
87                        $error = Errors::get($code);                   
88                        $message = ($responseException->getMessage() ? $responseException->getMessage() : $error['message']);                   
89                        $body['error'] = array("code" => $code, "message" => $message);         
90                        $response->body = json_encode($body);
91                        return $response;
92        }
93               
94}
Note: See TracBrowser for help on using the repository browser.