fix: use app.api_secret_key for self-API calls, handle ConnectionException
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Livewire\Public;
|
||||
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\View\View;
|
||||
use Livewire\Attributes\Validate;
|
||||
@@ -34,14 +35,20 @@ class StationSearch extends Component
|
||||
|
||||
$radiusKm = round($this->radius * 1.60934, 2);
|
||||
|
||||
try {
|
||||
$response = Http::timeout(10)
|
||||
->withHeaders(['X-Api-Key' => config('services.fuelalert.api_key')])
|
||||
->withHeaders(['X-Api-Key' => config('app.api_secret_key')])
|
||||
->get(url('/api/stations'), [
|
||||
'postcode' => $this->search,
|
||||
'fuel_type' => $this->fuelType,
|
||||
'radius' => $radiusKm,
|
||||
'sort' => 'price',
|
||||
]);
|
||||
} catch (ConnectionException) {
|
||||
$this->apiError = 'Unable to fetch stations. Please try again.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($response->status() === 422) {
|
||||
$errors = $response->json('errors', []);
|
||||
|
||||
Reference in New Issue
Block a user