I'm using Guzzle to push some data to an API using the following:
$total_price = round($total_price * 100, 0);
$client = new \GuzzleHttp\Client();
$callback = $client->request('GET', 'https://exaple.com/subscription.js', [
'query' => [
'aid' => 'c-a-totm-uk',
'tid' => $order_id,
'subid' => $reference,
'rvn' => $total_price,
'cid' => $customer_id,
]
]);
$status = $callback->getStatusCode();
It's not handling the errors/exceptions at the moment.
I've been looking at this question https://stackoverflow.com/a/28416973/609630 but am I right in saying with failures it will cause a fatal error before it hits the following code?
if (404 === $statuscode) {
// Clean up DB or something like this
} else {
throw new MyException("Invalid response from api...");
}
How can I handle it properly without causing a fatal error? I'd like to record what any errors are (I can do the recording part, just need to output the error).