hasErrors() public method

Informational 1xx Successful 2xx Redirection 3xx Client Error 4xx Server Error 5xx http://pretty-rfc.herokuapp.com/RFC2616#status.codes
public hasErrors ( ) : boolean
return boolean Did we receive a 4xx or 5xx?
コード例 #1
0
 /**
  * Handle the response returned by the server
  *
  * Child classes could override this method to do something with the response.
  * By default this class throws an exception when the response has han error
  *
  * @param \Httpful\Response $response
  * @Param CRM_Civirules_TriggerData_TriggerData $triggerData
  * @param \Httpful\Request $request
  * @throws \Exception
  */
 protected function handleResponse(\Httpful\Response $response, \Httpful\Request $request, CRM_Civirules_TriggerData_TriggerData $triggerData)
 {
     //by default throw an error if response is not a 200 response
     if ($response->hasErrors()) {
         throw new Exception('Invalid response. Got a HTTP ' . $response->code . "\r\n\r\n" . $response->raw_headers . "\r\n\r\n" . $response->raw_body . "\r\n\r\nRequest was: " . $request->method . ': ' . $request->uri . "\r\n" . $request->raw_headers . "\r\n\r\n" . $request->payload);
     }
     //do something with the response. You could override this method in a child class to do something with the response.
 }
コード例 #2
0
 /**
  * Build a single response to return to the user
  * @param array $event the event that the response is related to
  * @param \Httpful\Response $response The response from the API
  * @return Response
  */
 private function buildResponse($event, $response)
 {
     $success = !$response->hasErrors();
     $duplicate = $response->code == 409;
     $statusCode = $response->code;
     $errorMessage = null;
     if ($response->code == 401) {
         $errorMessage = 'Unauthorised. Please check your Project Id and API Key';
     }
     if ($response->body != null && $response->body->errorMessage != null) {
         $errorMessage = $response->body->errorMessage;
     }
     return new Response($success, $duplicate, $statusCode, $errorMessage, $event);
 }
コード例 #3
0
ファイル: HttpfulTest.php プロジェクト: noahkim/kowop
 function testHasErrors()
 {
     $req = Request::init()->sendsAndExpects(Mime::JSON);
     $response = new Response('', "HTTP/1.1 100 Continue\r\n", $req);
     $this->assertFalse($response->hasErrors());
     $response = new Response('', "HTTP/1.1 200 OK\r\n", $req);
     $this->assertFalse($response->hasErrors());
     $response = new Response('', "HTTP/1.1 300 Multiple Choices\r\n", $req);
     $this->assertFalse($response->hasErrors());
     $response = new Response('', "HTTP/1.1 400 Bad Request\r\n", $req);
     $this->assertTrue($response->hasErrors());
     $response = new Response('', "HTTP/1.1 500 Internal Server Error\r\n", $req);
     $this->assertTrue($response->hasErrors());
 }