axios-apicloud-adapter
Advanced tools
Comparing version 0.0.1 to 0.1.0
41
index.js
import axios from 'axios' | ||
import utils from 'axios/lib/utils' | ||
import settle from 'axios/lib/core/settle' | ||
@@ -17,7 +18,7 @@ import httpAdapter from 'axios/lib/adapters/http' | ||
encode: config.encode, | ||
tag: config.tag, | ||
tag: config.cancelToken, | ||
cache: config.cache, | ||
timeout: config.timeout, | ||
dataType: config.dataType, | ||
charset: config.charset, | ||
dataType: config.responseType, | ||
charset: config.responseEncoding, | ||
headers: config.headers, | ||
@@ -31,5 +32,3 @@ report: config.report, | ||
const dataType = config.data.toString() | ||
if (dataType === '[object FormData]') { | ||
if (utils.isFormData(config.data)) { | ||
params.data.values = {} | ||
@@ -39,3 +38,3 @@ params.data.files = {} | ||
const [key, value] = data | ||
if (value.toString() === '[object File]') { | ||
if (utils.isFile(value)) { | ||
params.data.files[key] = value | ||
@@ -75,9 +74,15 @@ } else { | ||
const transformError = (error, reject, config) => { | ||
const { code } = error | ||
if (code === 1) { | ||
// timeout | ||
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', '')) | ||
const { code, msg } = error | ||
if (code === 0) { | ||
reject(createError('连接错误', config, msg)) | ||
} else if (code === 1) { | ||
reject(createError('超出 ' + config.timeout + 'ms 的超时限制', config, 'ECONNABORTED', '')) | ||
} else if (code === 2) { | ||
reject(createError('授权错误', config, msg)) | ||
} else if (code === 3) { | ||
reject(createError('数据类型错误', config, msg)) | ||
} else if (code === 4) { | ||
reject(createError('不安全的数据', config, msg)) | ||
} else { | ||
// NetWordError | ||
reject(createError('Network Error', config, null, '')) | ||
reject(createError('网络错误', config, null, '')) | ||
} | ||
@@ -97,3 +102,13 @@ } | ||
}) | ||
if (config.cancelToken) { | ||
// Handle cancellation | ||
config.cancelToken.promise.then((cancel) => { | ||
window.api.cancelAjax({ | ||
tag: config.cancelToken | ||
}) | ||
reject(cancel) | ||
}) | ||
} | ||
}) | ||
} |
{ | ||
"name": "axios-apicloud-adapter", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "axios 的 apicloud 适配器,以便于在 app 中使用原生网络请求库", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3979
98