HTTP client error handling not working when localhost is not available
Am unable to catch this request error when no application is available to respond to the request:
try{
$response = Http::withHeaders([
'Content-Type' => 'application/json'
])
->accept('application/json')
->post('http://localhost:8088/save',$sendData);
}catch(\Exception $e) {
//can't save $sendData for later use
}
$sendData is properly formatted so it's can't be the issue. When I switch on the external application responding at localhost:8088, everything works since there's no error.
@aleahy[2024-06-10 06:47:21] local.ERROR: cURL error 7: Failed to connect to localhost port 8088: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8088/save {"userId":1,"exception":"[object] (Illuminate\\Http\\Client\\ConnectionException(code: 0): cURL error 7: Failed to connect to localhost port 8088: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8088/save at /home//src/vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php:855)