fix: 增加对不支持的 HTTP 方法的错误处理

This commit is contained in:
lighua
2025-08-21 11:13:02 +08:00
parent df655015b1
commit fddfc6d494
2 changed files with 91 additions and 2 deletions

View File

@@ -33,9 +33,27 @@ class FileDownloader {
responseType: 'blob',
};
const response = await this.client.request<T>(url, finalConfig);
// Prefer a generic request if available; otherwise, dispatch to method-specific calls.
const method = (finalConfig.method || 'GET').toUpperCase();
const clientAny = this.client as any;
return response;
if (typeof clientAny.request === 'function') {
return await clientAny.request(url, finalConfig);
}
const lower = method.toLowerCase();
if (typeof clientAny[lower] === 'function') {
if (['POST', 'PUT'].includes(method)) {
const { data, ...rest } = finalConfig as Record<string, any>;
return await clientAny[lower](url, data, rest);
}
return await clientAny[lower](url, finalConfig);
}
throw new Error(
`RequestClient does not support method "${method}". Please ensure the method is properly implemented in your RequestClient instance.`,
);
}
}