/** * Tests the http request response result. */ public function testHttpRequestResponseResult() { $response = new NostoHttpResponse(array(), json_encode(array('test' => true))); $this->assertEquals('{"test":true}', $response->getResult()); $result = $response->getJsonResult(true); $this->assertArrayHasKey('test', $result); $this->assertContains(true, $result); }
/** * Throws a new NostoHttpException exception with info about both the * request and response. * * @param string $message the error message. * @param NostoHttpRequest $request the request object to take additional info from. * @param NostoHttpResponse $response the response object to take additional info from. * @throws NostoHttpException|NostoApiResponseException the exception. */ public static function throwHttpException($message, NostoHttpRequest $request, NostoHttpResponse $response) { $jsonResponse = $response->getJsonResult(); if (isset($jsonResponse->type) && isset($jsonResponse->message)) { if (isset($jsonResponse->message)) { $message .= '. ' . $jsonResponse->message; } throw new NostoApiResponseException($message, $response->getCode(), null, $request, $response); } else { if ($response->getMessage()) { $message .= '. ' . $response->getMessage(); } throw new NostoHttpException($message, $response->getCode(), null, $request, $response); } }