|
@@ -129,7 +129,7 @@ export class VAxios {
|
|
|
} else {
|
|
|
formData.append(customFilename, params.file);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (params.data) {
|
|
|
Object.keys(params.data).forEach((key) => {
|
|
|
const value = params.data![key];
|
|
@@ -144,15 +144,45 @@ export class VAxios {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- return this.axiosInstance.request<T>({
|
|
|
- ...config,
|
|
|
- method: 'POST',
|
|
|
- data: formData,
|
|
|
- headers: {
|
|
|
- 'Content-type': ContentTypeEnum.FORM_DATA,
|
|
|
- // @ts-ignore
|
|
|
- ignoreCancelToken: true,
|
|
|
- },
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const transform = this.getTransform();
|
|
|
+
|
|
|
+ const { requestOptions } = this.options;
|
|
|
+
|
|
|
+ const opt: RequestOptions = Object.assign({}, requestOptions,);
|
|
|
+
|
|
|
+ const { requestCatchHook, transformRequestHook } = transform || {};
|
|
|
+ this.axiosInstance.request<any, AxiosResponse<Result>>({
|
|
|
+ ...config,
|
|
|
+ method: 'POST',
|
|
|
+ data: formData,
|
|
|
+ headers: {
|
|
|
+ 'Content-type': ContentTypeEnum.FORM_DATA,
|
|
|
+ // @ts-ignore
|
|
|
+ ignoreCancelToken: true,
|
|
|
+ },
|
|
|
+ }).then((res: AxiosResponse<Result>) => {
|
|
|
+ if (transformRequestHook && isFunction(transformRequestHook)) {
|
|
|
+ try {
|
|
|
+ const ret = transformRequestHook(res, opt);
|
|
|
+ resolve(ret);
|
|
|
+ } catch (err) {
|
|
|
+ reject(err || new Error('request error!'));
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ resolve(res as unknown as Promise<T>);
|
|
|
+ })
|
|
|
+ .catch((e: Error | AxiosError) => {
|
|
|
+ if (requestCatchHook && isFunction(requestCatchHook)) {
|
|
|
+ reject(requestCatchHook(e, opt));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (axios.isAxiosError(e)) {
|
|
|
+ // rewrite error message from axios in here
|
|
|
+ }
|
|
|
+ reject(e);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -161,7 +191,7 @@ export class VAxios {
|
|
|
* @description: File Upload
|
|
|
*/
|
|
|
downloadFile<T = any>(config: AxiosRequestConfig) {
|
|
|
- return this.axiosInstance.request<T>({
|
|
|
+ return this.request({
|
|
|
...config,
|
|
|
headers: {
|
|
|
'Content-type': ContentTypeEnum.JSON,
|