/** * Creates 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. * @return NostoHttpException the exception. */ public static function createHttpException($message, NostoHttpRequest $request, NostoHttpResponse $response) { $message .= sprintf(' Error: %s.', $response->getCode()); $message .= sprintf(' Request: %s.', $request); $message .= sprintf(' Response: %s.', $response); return new NostoHttpException($message, $response->getCode()); }
/** * 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); } }