Enhancement: axiosInstance: no error handling/interceptors & env validation #7
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
axiosInstance: no error handling/interceptors & env validation
Description
The current Axios instance is minimally configured with a
baseURLsourced fromimport.meta.env.VITE_API_URLand a fixed timeout value.The implementation lacks:
VITE_API_URLThis creates inconsistent API behavior across the application and increases the likelihood of hard-to-debug networking issues.
Impact
VITE_API_URLis missing or misconfigured.Location
src/api/axiosInstance.tsApproximate Lines
~3–9
Suggested Fix
1. Validate Environment Configuration
Verify that
VITE_API_URLexists during application startup.Fail fast with a clear and actionable error message if the variable is missing.
Example
2. Add Request Interceptor
Introduce a centralized request interceptor for:
Example responsibilities:
3. Add Response Interceptor
Normalize API errors into a consistent format.
Handle common cases:
Example:
4. Retry Transient Failures
Consider automatic retries for:
Recommended approaches:
5. Define Authentication Strategy
If authentication is planned:
Acceptance Criteria
VITE_API_URLduring application startup.Local Verification
Run the following commands before creating the PR.
Build
Lint Check
Manual Testing
Environment Validation
VITE_API_URL.VITE_API_URL.Error Handling
Authentication (If Implemented)