Catch API error
I have some code like below
$response = Http::post('sometext/api/v1/user/login', [
'email' => $request->email,
'password' => $request->password
]);
Often I get error like below
ConnectionException
cURL error 6: Could not resolve host:
How can I catch the error ?
Is it possible to catch the error using below code ?
if (empty($response)) {
// some code
}
Wrap it inside a try-catch block.
try {
$response = Http::post('sometext/api/v1/user/login', [
'email' => $request->email,
'password' => $request->password
]);
} catch (Exception $exception) {
// Do whatever
}
Please or to participate in this conversation.