Refactor error handling and enhance API interactions across Filament pages

- Introduced `ApiErrorTranslator` to normalize and translate API error messages, providing clearer feedback in French.
- Updated all Filament pages (Articles, Documents, Divers, Journaux, Tiers, TablesExplorer) to utilize the new error translation mechanism, improving user experience during API interactions.
- Added validation for required fields before API calls, ensuring users receive immediate feedback when mandatory inputs are missing.
- Implemented tracking properties to distinguish between "never searched" and "searched without results," enhancing the user interface.
- Removed the obsolete `$results` property from the Articles page and added a new `$barcode` property to align with API requirements.
- Updated documentation to reflect changes in API behavior and error handling, including new metadata returned by the `art_list` endpoint.
- Added new tests to verify the functionality of the barcode handling and validation logic.
This commit is contained in:
2026-02-23 10:15:17 +01:00
parent 7df94b64fa
commit bb1bbc2904
29 changed files with 1075 additions and 157 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
use App\Exceptions\LogisticsApiException;
use App\Services\LogisticsService;
use App\Support\ApiErrorTranslator;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Livewire\Attributes\Url;
@@ -92,11 +93,11 @@ class TablesExplorer extends Page
$this->tables = $response['data'] ?? [];
$this->tablesMetadata = $response['metadata'] ?? null;
$this->errorMessage = $response['error'] ?? null;
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
}
}
@@ -116,12 +117,12 @@ class TablesExplorer extends Page
$rawColumns = $response['data'] ?? [];
$this->columns = $this->deduplicateColumns($rawColumns);
$this->columnsMetadata = $response['metadata'] ?? null;
$this->errorMessage = $response['error'] ?? null;
$this->errorMessage = ApiErrorTranslator::translate($response['error'] ?? null);
} catch (LogisticsApiException $e) {
$this->errorMessage = $e->getMessage();
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->columns = [];
} catch (\Throwable $e) {
$this->errorMessage = "Erreur inattendue : {$e->getMessage()}";
$this->errorMessage = ApiErrorTranslator::translate($e->getMessage());
$this->columns = [];
}
}