本文整理汇总了TypeScript中axios.isCancel函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isCancel函数的具体用法?TypeScript isCancel怎么用?TypeScript isCancel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isCancel函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: curry
const convertResponse = curry((startedAt: number, axiosResult: AxiosResponse | AxiosError) => {
const end: number = toNumber(new Date())
const duration: number = end - startedAt
// new in Axios 0.13 -- some data could be buried 1 level now
const isError = axiosResult instanceof Error || axios.isCancel(axiosResult)
const axiosResponse = axiosResult as AxiosResponse
const axiosError = axiosResult as AxiosError
const response = isError ? axiosError.response : axiosResponse
const status = (response && response.status) || null
const problem = isError ? getProblemFromError(axiosResult) : getProblemFromStatus(status)
const originalError = isError ? axiosError : null
const ok = in200s(status)
const config = axiosResult.config || null
const headers = (response && response.headers) || null
let data = (response && response.data) || null
// give an opportunity for anything to the response transforms to change stuff along the way
let transformedResponse = {
duration,
problem,
originalError,
ok,
status,
headers,
config,
data,
}
if (responseTransforms.length > 0) {
forEach(transform => transform(transformedResponse), responseTransforms)
}
return transformedResponse
})
示例2: dispatch
}).catch(error => {
if (axios.isCancel(error)) {
console.warn(error.message);
} else {
dispatch({ ...payload, type: failureType, ...onError(error) });
}
});
示例3: handleReqError
function handleReqError(err, onError) {
if (Axios.isCancel(err)) {
return Promise.reject(err);
}
if (_.isFunction(onError)) {
return onError(err);
}
return Promise.reject(err);
}
示例4: cond
export const getProblemFromError = error => {
// first check if the error message is Network Error (set by axios at 0.12) on platforms other than NodeJS.
if (error.message === 'Network Error') return NETWORK_ERROR
if (axios.isCancel(error)) return CANCEL_ERROR
// then check the specific error code
return cond([
// if we don't have an error code, we have a response status
[isNil, () => getProblemFromStatus(statusNil(error.response))],
[containsText(TIMEOUT_ERROR_CODES), always(TIMEOUT_ERROR)],
[containsText(NODEJS_CONNECTION_ERROR_CODES), always(CONNECTION_ERROR)],
[T, always(UNKNOWN_ERROR)],
])(error.code)
}
示例5:
.catch(error => (axios.isCancel(error) ? Promise.resolve('') : Promise.reject(error)));