Merge pull request #15 from fluffff/v2.0.0-rc-1

chore: v2.0.0-rc-1
pull/16/head
初秋 2021-05-24 21:36:09 +08:00 committed by GitHub
commit c447ae06fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 27 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "axios-miniprogram", "name": "axios-miniprogram",
"version": "2.0.0_rc_1", "version": "v2.0.0-rc-1",
"description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。", "description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。",
"main": "dist/cjs/axios-miniprogram.js", "main": "dist/cjs/axios-miniprogram.js",
"module": "dist/esm/axios-miniprogram.js", "module": "dist/esm/axios-miniprogram.js",

View File

@ -92,41 +92,41 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
'platform.request 与 platform.download 和 platform.upload 需要是一个 Function 类型', 'platform.request 与 platform.download 和 platform.upload 需要是一个 Function 类型',
); );
function transformCommon(common: any): void { function transformResult(result: any): void {
if (!isUndefined(common.statusCode)) { if (!isUndefined(result.statusCode)) {
common.status = common.statusCode; result.status = result.statusCode;
delete common.statusCode; delete result.statusCode;
} }
if (isUndefined(common.status)) { if (isUndefined(result.status)) {
common.status = isUndefined(common.data) ? 400 : 200; result.status = isUndefined(result.data) ? 400 : 200;
} }
if (!isUndefined(common.header)) { if (!isUndefined(result.header)) {
common.headers = common.header; result.headers = result.header;
delete common.header; delete result.header;
} }
if (isUndefined(common.headers)) { if (isUndefined(result.headers)) {
common.headers = {}; result.headers = {};
} }
if (!isUndefined(common.errMsg)) { if (!isUndefined(result.errMsg)) {
common.statusText = common.errMsg; result.statusText = result.errMsg;
delete common.errMsg; delete result.errMsg;
} }
if (isUndefined(common.statusText)) { if (isUndefined(result.statusText)) {
common.statusText = result.statusText =
common.status === 200 result.status === 200
? 'OK' ? 'OK'
: common.status === 400 : result.status === 400
? 'Bad Adapter' ? 'Bad Adapter'
: ''; : '';
} }
} }
function generateDownloadResponseData(response: any): void { function injectDownloadData(response: any): void {
if (!isPlainObject(response.data)) { if (!isPlainObject(response.data)) {
response.data = {}; response.data = {};
} }
@ -154,11 +154,11 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
const options = Object.assign({}, config, { const options = Object.assign({}, config, {
header: config.headers, header: config.headers,
success(response: any): void { success(response: any): void {
transformCommon(response); transformResult(response);
config.success(response); config.success(response);
}, },
fail(error: any): void { fail(error: any): void {
transformCommon(error); transformResult(error);
config.fail(error); config.fail(error);
}, },
}); });
@ -186,11 +186,11 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
hideLoading, hideLoading,
formData, formData,
success(response: any): void { success(response: any): void {
transformCommon(response); transformResult(response);
config.success(response); config.success(response);
}, },
fail(error: any): void { fail(error: any): void {
transformCommon(error); transformResult(error);
config.fail(error); config.fail(error);
}, },
}); });
@ -207,12 +207,12 @@ export function createAdapter(platform: AxiosPlatform): AxiosAdapter {
filePath: config.params?.filePath, filePath: config.params?.filePath,
fileName: config.params?.fileName, fileName: config.params?.fileName,
success(response: any): void { success(response: any): void {
generateDownloadResponseData(response); injectDownloadData(response);
transformCommon(response); transformResult(response);
config.success(response); config.success(response);
}, },
fail(error: any): void { fail(error: any): void {
transformCommon(error); transformResult(error);
config.fail(error); config.fail(error);
}, },
}); });