fix: add dynamic timeout for document uploads (refs #33)
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m43s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 37s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
All checks were successful
Deploy to Staging / Build Images (pull_request) Successful in 2m43s
Deploy to Staging / Deploy to Staging (pull_request) Successful in 37s
Deploy to Staging / Verify Staging (pull_request) Successful in 7s
Deploy to Staging / Notify Staging Ready (pull_request) Successful in 6s
Deploy to Staging / Notify Staging Failure (pull_request) Has been skipped
Document uploads were failing with "timeout of 10000ms exceeded" error because the global axios client timeout (10s) was too short for medium-sized files (1-5MB). Added calculateUploadTimeout() function that calculates timeout based on file size: 30s base + 10s per MB. This allows uploads to complete on slower connections while still having reasonable timeout limits. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
import { apiClient } from '../../../core/api/client';
|
||||
import type { CreateDocumentRequest, DocumentRecord, UpdateDocumentRequest } from '../types/documents.types';
|
||||
|
||||
/**
|
||||
* Calculate upload timeout based on file size.
|
||||
* Base: 30 seconds + 10 seconds per MB to accommodate slow connections.
|
||||
*/
|
||||
function calculateUploadTimeout(file: File): number {
|
||||
const fileSizeMB = file.size / (1024 * 1024);
|
||||
const baseTimeout = 30000; // 30 seconds minimum
|
||||
const perMBTimeout = 10000; // 10 seconds per MB
|
||||
return Math.round(baseTimeout + fileSizeMB * perMBTimeout);
|
||||
}
|
||||
|
||||
export const documentsApi = {
|
||||
async list(params?: { vehicleId?: string; type?: string; expiresBefore?: string }) {
|
||||
const res = await apiClient.get<DocumentRecord[]>('/documents', { params });
|
||||
@@ -26,6 +37,7 @@ export const documentsApi = {
|
||||
form.append('file', file);
|
||||
const res = await apiClient.post<DocumentRecord>(`/documents/${id}/upload`, form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: calculateUploadTimeout(file),
|
||||
});
|
||||
return res.data;
|
||||
},
|
||||
@@ -34,6 +46,7 @@ export const documentsApi = {
|
||||
form.append('file', file);
|
||||
const res = await apiClient.post<DocumentRecord>(`/documents/${id}/upload`, form, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
timeout: calculateUploadTimeout(file),
|
||||
onUploadProgress: (evt) => {
|
||||
if (evt.total) {
|
||||
const pct = Math.round((evt.loaded / evt.total) * 100);
|
||||
|
||||
Reference in New Issue
Block a user