Files
logisticsAPI/app/Filament/Pages/Documents.php
Marvin 4aef33f270 Implement robust error handling and configuration for Logistics API interactions
- 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.
2026-02-20 10:06:04 +01:00

83 lines
2.3 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 Documents extends Page
{
protected static string|\BackedEnum|null $navigationIcon = Heroicon::OutlinedDocumentText;
protected static ?string $navigationLabel = 'Documents';
protected static ?string $title = 'Documents';
protected static ?int $navigationSort = 3;
protected string $view = 'filament.pages.documents';
public string $select = 'jnl,number,thirdid,date';
public string $thirdId = '';
public string $detailJnl = '';
public string $detailNumber = '';
public array $data = [];
public array $detailData = [];
public ?array $metadata = null;
public ?string $errorMessage = null;
public function searchDocuments(): void
{
try {
$service = app(LogisticsService::class);
$params = array_filter([
'select' => $this->select,
'thirdid' => $this->thirdId,
]);
$response = $service->documentList($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 getDocumentDetail(): void
{
if (blank($this->detailJnl) || blank($this->detailNumber)) {
return;
}
try {
$service = app(LogisticsService::class);
$response = $service->documentDetail($this->detailJnl, $this->detailNumber);
$this->detailData = $response['data'] ?? [];
$this->errorMessage = $response['error'] ?? null;
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->detailData = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->detailData = [];
}
}
}