Refactor OpenAPI fetcher for improved clarity and robustness
Reorganized and enhanced the OpenAPI fetch logic for better maintainability and error handling. Key updates include improved environment variable validation, more detailed error messages, streamlined configuration loading, and additional safety checks for file paths and directories. Added proper logging and ensured the process flow is easy to trace.
This commit is contained in:
parent
2360e0718d
commit
bd63dc3c91
@ -92,10 +92,26 @@ const LogisticsView: React.FC = () => {
|
|||||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isTestEnv = import.meta.env.MODE === 'test';
|
// Detect the current environment
|
||||||
OpenAPI.BASE = isTestEnv
|
const mode = import.meta.env.MODE;
|
||||||
|
|
||||||
|
// Dynamically set `OpenAPI.BASE` based on the mode
|
||||||
|
OpenAPI.BASE =
|
||||||
|
mode === 'test'
|
||||||
? import.meta.env.VITE_OPENAPI_BASE_TEST
|
? import.meta.env.VITE_OPENAPI_BASE_TEST
|
||||||
|
: mode === 'prod'
|
||||||
|
? import.meta.env.VITE_OPENAPI_BASE_PROD
|
||||||
: import.meta.env.VITE_OPENAPI_BASE_DEV;
|
: import.meta.env.VITE_OPENAPI_BASE_DEV;
|
||||||
|
|
||||||
|
// Log warning if `OpenAPI.BASE` is unresolved
|
||||||
|
if (!OpenAPI.BASE) {
|
||||||
|
console.error('OpenAPI.BASE is not set. Falling back to a default value.');
|
||||||
|
OpenAPI.BASE = 'https://default-url.com'; // Use a consistent fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug for mode and resolved `BASE`
|
||||||
|
console.log('Environment Mode:', mode);
|
||||||
|
console.log('Resolved OpenAPI.BASE:', OpenAPI.BASE);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchDewarsAndSlots = async () => {
|
const fetchDewarsAndSlots = async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user