저는 laravel을 사용하고 있습니다. 저는 다양한 API에서 응답을 얻기 위해 추상 클래스 메소드를 설정했습니다. 그러나 API url에 도달 할 수없는 경우 예외가 발생합니다. 나는 뭔가를 놓친다는 것을 안다. 어떤 도움이 나를 위해 위대한 것입니다.놀이터에서 예외 잡기
$offers = [];
try {
$appUrl = parse_url($this->apiUrl);
// Call Api using Guzzle
$client = new Client('' . $appUrl['scheme'] . '://' . $appUrl['host'] . '' . $appUrl['path']);
if ($appUrl['scheme'] == 'https') //If https then disable ssl certificate
$client->setDefaultOption('verify', false);
$request = $client->get('?' . $appUrl['query']);
$response = $request->send();
if ($response->getStatusCode() == 200) {
$offers = json_decode($response->getBody(), true);
}
} catch (ClientErrorResponseException $e) {
Log::info("Client error :" . $e->getResponse()->getBody(true));
} catch (ServerErrorResponseException $e) {
Log::info("Server error" . $e->getResponse()->getBody(true));
} catch (BadResponseException $e) {
Log::info("BadResponse error" . $e->getResponse()->getBody(true));
} catch (\Exception $e) {
Log::info("Err" . $e->getMessage());
}
return $offers;