Esempio n. 1
0
 /**
  * @depends testFormatJson
  */
 public function testSet_error_code()
 {
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_code(400);
     $this->assertErrorMessage($api_result, 400, API_V1_result::ERROR_BAD_REQUEST, API_V1_exception_badrequest::get_details(), null);
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_code(401);
     $this->assertErrorMessage($api_result, 401, API_V1_result::ERROR_UNAUTHORIZED, API_V1_exception_unauthorized::get_details(), null);
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_code(403);
     $this->assertErrorMessage($api_result, 403, API_V1_result::ERROR_FORBIDDEN, API_V1_exception_forbidden::get_details(), null);
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_code(404);
     $this->assertErrorMessage($api_result, 404, API_V1_result::ERROR_NOTFOUND, API_V1_exception_notfound::get_details(), null);
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_code(405);
     $this->assertErrorMessage($api_result, 405, API_V1_result::ERROR_METHODNOTALLOWED, API_V1_exception_methodnotallowed::get_details(), null);
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_code(500);
     $this->assertErrorMessage($api_result, 500, API_V1_result::ERROR_INTERNALSERVERERROR, API_V1_exception_internalservererror::get_details(), null);
 }
Esempio n. 2
0
 /**
  * Set the API_V1_result http_code, error_message and error_details
  * with the appropriate datas
  *
  * @param integer $code
  *
  * @return API_V1_result
  */
 public function set_error_code($code)
 {
     switch ($code = (int) $code) {
         case 400:
             $this->http_code = $code;
             $this->error_type = self::ERROR_BAD_REQUEST;
             $this->error_message = API_V1_exception_badrequest::get_details();
             break;
         case 401:
             $this->http_code = $code;
             $this->error_type = self::ERROR_UNAUTHORIZED;
             $this->error_message = API_V1_exception_unauthorized::get_details();
             break;
         case 403:
             $this->http_code = $code;
             $this->error_type = self::ERROR_FORBIDDEN;
             $this->error_message = API_V1_exception_forbidden::get_details();
             break;
         case 404:
             $this->http_code = $code;
             $this->error_type = self::ERROR_NOTFOUND;
             $this->error_message = API_V1_exception_notfound::get_details();
             break;
         case 405:
             $this->http_code = $code;
             $this->error_type = self::ERROR_METHODNOTALLOWED;
             $this->error_message = API_V1_exception_methodnotallowed::get_details();
             break;
         case 500:
             $this->http_code = $code;
             $this->error_type = self::ERROR_INTERNALSERVERERROR;
             $this->error_message = API_V1_exception_internalservererror::get_details();
             break;
     }
     return $this;
 }