From 3fc5ac350709b060adfcbc1c77c0b261f0c93743 Mon Sep 17 00:00:00 2001 From: "954270063@qq.com" <954270063@qq.com> Date: Mon, 24 May 2021 21:25:07 +0800 Subject: [PATCH] chore: v2.0.0-rc-1 --- package.json | 2 +- src/core/adapter.ts | 52 ++++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 3f1ce79..68609e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "axios-miniprogram", - "version": "2.0.0_rc_1", + "version": "v2.0.0-rc-1", "description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。", "main": "dist/cjs/axios-miniprogram.js", "module": "dist/esm/axios-miniprogram.js", diff --git a/src/core/adapter.ts b/src/core/adapter.ts index a53aabc..6562c78 100644 --- a/src/core/adapter.ts +++ b/src/core/adapter.ts @@ -92,41 +92,41 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter { 'platform.request 与 platform.download 和 platform.upload 需要是一个 Function 类型', ); - function transformCommon(common: any): void { - if (!isUndefined(common.statusCode)) { - common.status = common.statusCode; - delete common.statusCode; + function transformResult(result: any): void { + if (!isUndefined(result.statusCode)) { + result.status = result.statusCode; + delete result.statusCode; } - if (isUndefined(common.status)) { - common.status = isUndefined(common.data) ? 400 : 200; + if (isUndefined(result.status)) { + result.status = isUndefined(result.data) ? 400 : 200; } - if (!isUndefined(common.header)) { - common.headers = common.header; - delete common.header; + if (!isUndefined(result.header)) { + result.headers = result.header; + delete result.header; } - if (isUndefined(common.headers)) { - common.headers = {}; + if (isUndefined(result.headers)) { + result.headers = {}; } - if (!isUndefined(common.errMsg)) { - common.statusText = common.errMsg; - delete common.errMsg; + if (!isUndefined(result.errMsg)) { + result.statusText = result.errMsg; + delete result.errMsg; } - if (isUndefined(common.statusText)) { - common.statusText = - common.status === 200 + if (isUndefined(result.statusText)) { + result.statusText = + result.status === 200 ? 'OK' - : common.status === 400 + : result.status === 400 ? 'Bad Adapter' : ''; } } - function generateDownloadResponseData(response: any): void { + function injectDownloadData(response: any): void { if (!isPlainObject(response.data)) { response.data = {}; } @@ -154,11 +154,11 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter { const options = Object.assign({}, config, { header: config.headers, success(response: any): void { - transformCommon(response); + transformResult(response); config.success(response); }, fail(error: any): void { - transformCommon(error); + transformResult(error); config.fail(error); }, }); @@ -186,11 +186,11 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter { hideLoading, formData, success(response: any): void { - transformCommon(response); + transformResult(response); config.success(response); }, fail(error: any): void { - transformCommon(error); + transformResult(error); config.fail(error); }, }); @@ -207,12 +207,12 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter { filePath: config.params?.filePath, fileName: config.params?.fileName, success(response: any): void { - generateDownloadResponseData(response); - transformCommon(response); + injectDownloadData(response); + transformResult(response); config.success(response); }, fail(error: any): void { - transformCommon(error); + transformResult(error); config.fail(error); }, });