- Introduced `LogisticsApiException` to handle connection and request errors with user-friendly messages in French. - Updated `LogisticsService` to include configurable timeout, connection timeout, retry attempts, and sleep duration for retries. - Enhanced error handling in Filament pages to catch `LogisticsApiException` and provide clear feedback to users. - Updated `.env` and `config/logistics.php` to support new configuration options. - Added logging for failed API requests in `api_request_logs`. - Created comprehensive API documentation for Logistics endpoints.
84 lines
2.2 KiB
PHP
84 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Exceptions\LogisticsApiException;
|
|
use App\Services\LogisticsService;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Icons\Heroicon;
|
|
|
|
class Articles extends Page
|
|
{
|
|
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedCube;
|
|
|
|
protected static ?string $navigationLabel = 'Articles';
|
|
|
|
protected static ?string $title = 'Articles';
|
|
|
|
protected static ?int $navigationSort = 2;
|
|
|
|
protected string $view = 'filament.pages.articles';
|
|
|
|
public string $search = '';
|
|
|
|
public string $select = 'artid,artname';
|
|
|
|
public int $results = 10;
|
|
|
|
public string $stockArticleId = '';
|
|
|
|
public array $data = [];
|
|
|
|
public array $stockData = [];
|
|
|
|
public ?array $metadata = null;
|
|
|
|
public ?string $errorMessage = null;
|
|
|
|
public function searchArticles(): void
|
|
{
|
|
try {
|
|
$service = app(LogisticsService::class);
|
|
|
|
$params = array_filter([
|
|
'select' => $this->select,
|
|
'results' => $this->results,
|
|
'search' => $this->search,
|
|
]);
|
|
|
|
$response = $service->artList($params);
|
|
|
|
$this->data = $response['data'] ?? [];
|
|
$this->metadata = $response['metadata'] ?? null;
|
|
$this->errorMessage = $response['error'] ?? null;
|
|
} catch (LogisticsApiException $e) {
|
|
$this->errorMessage = $e->getMessage();
|
|
$this->data = [];
|
|
} catch (\Throwable $e) {
|
|
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
|
|
$this->data = [];
|
|
}
|
|
}
|
|
|
|
public function getStock(): void
|
|
{
|
|
if (blank($this->stockArticleId)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$service = app(LogisticsService::class);
|
|
$response = $service->artGetStock($this->stockArticleId);
|
|
|
|
$this->stockData = $response['data'] ?? [];
|
|
$this->errorMessage = $response['error'] ?? null;
|
|
} catch (LogisticsApiException $e) {
|
|
$this->errorMessage = $e->getMessage();
|
|
$this->stockData = [];
|
|
} catch (\Throwable $e) {
|
|
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
|
|
$this->stockData = [];
|
|
}
|
|
}
|
|
}
|