fix: use app.api_secret_key for self-API calls, handle ConnectionException

This commit is contained in:
Ovidiu U
2026-04-05 20:41:23 +01:00
parent a034e5cd6d
commit f05a617af0

View File

@@ -2,6 +2,7 @@
namespace App\Livewire\Public; namespace App\Livewire\Public;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\View\View; use Illuminate\View\View;
use Livewire\Attributes\Validate; use Livewire\Attributes\Validate;
@@ -34,14 +35,20 @@ class StationSearch extends Component
$radiusKm = round($this->radius * 1.60934, 2); $radiusKm = round($this->radius * 1.60934, 2);
try {
$response = Http::timeout(10) $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'), [ ->get(url('/api/stations'), [
'postcode' => $this->search, 'postcode' => $this->search,
'fuel_type' => $this->fuelType, 'fuel_type' => $this->fuelType,
'radius' => $radiusKm, 'radius' => $radiusKm,
'sort' => 'price', 'sort' => 'price',
]); ]);
} catch (ConnectionException) {
$this->apiError = 'Unable to fetch stations. Please try again.';
return;
}
if ($response->status() === 422) { if ($response->status() === 422) {
$errors = $response->json('errors', []); $errors = $response->json('errors', []);