mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
fix: request skipErrorHandler 配置问题 (#121)
* fix: request skipErrorHandler 配置问题 * fix: 处理 default 异常问题?
This commit is contained in:
parent
91a5d71654
commit
c946536e8e
@ -142,29 +142,37 @@ function skipErrorHandlerToObj(skipErrorHandler = []) {
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getErrorKey(error, response) {
|
||||||
|
const resCode = getResponseCode(response);
|
||||||
|
|
||||||
|
if (resCode) return resCode;
|
||||||
|
if (error.type) return error.type;
|
||||||
|
return error.response?.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSkipErrorHandler(config, errorKey) {
|
||||||
|
// 跳过所有错误类型处理
|
||||||
|
if (config.skipErrorHandler === true) return true;
|
||||||
|
|
||||||
|
const skipObj = skipErrorHandlerToObj(config.skipErrorHandler);
|
||||||
|
|
||||||
|
return skipObj[errorKey];
|
||||||
|
}
|
||||||
|
|
||||||
function handleRequestError({
|
function handleRequestError({
|
||||||
errorHandler = {},
|
errorHandler = {},
|
||||||
error,
|
error,
|
||||||
response,
|
response,
|
||||||
config
|
config
|
||||||
}) {
|
}) {
|
||||||
// 跳过所有错误类型处理
|
const errorKey = getErrorKey(error, response);
|
||||||
if (config.skipErrorHandler === true) return;
|
|
||||||
|
|
||||||
const skipObj = skipErrorHandlerToObj(config.skipErrorHandler);
|
if (!isSkipErrorHandler(config, errorKey)) {
|
||||||
const resCode = getResponseCode(response);
|
if (isFunction(errorHandler[errorKey])) {
|
||||||
|
errorHandler[errorKey](error, response);
|
||||||
let errorKey = 'default';
|
} else if (isFunction(errorHandler.default)) {
|
||||||
if (resCode && errorHandler[resCode]) {
|
errorHandler.default(error, response);
|
||||||
errorKey = resCode;
|
}
|
||||||
} else if (error.type && errorHandler[error.type]) {
|
|
||||||
errorKey = error.type;
|
|
||||||
} else if (error.response && errorHandler[error.response.status]) {
|
|
||||||
errorKey = error.response.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!skipObj[errorKey] && errorHandler[errorKey]) {
|
|
||||||
return errorHandler[errorKey](error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ export const request = {
|
|||||||
console.log('500 error');
|
console.log('500 error');
|
||||||
},
|
},
|
||||||
default(error) {
|
default(error) {
|
||||||
console.log(error);
|
console.log('default error', error);
|
||||||
const msg = error?.data?.msg || error?.msg;
|
const msg = error?.data?.msg || error?.msg;
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
}
|
}
|
||||||
|
@ -38,108 +38,17 @@ export default {
|
|||||||
console.log('click Icon');
|
console.log('click Icon');
|
||||||
};
|
};
|
||||||
console.log(useRoute());
|
console.log(useRoute());
|
||||||
// request('/api', null, {
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// mergeRequest: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// mergeRequest: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// throttle: 3000,
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
|
|
||||||
const get = (id) => {
|
const get = () => {
|
||||||
request(
|
request('/api', null, {
|
||||||
'/get/api',
|
skipErrorHandler: ['500']
|
||||||
{ id },
|
}).catch((err) => {
|
||||||
{
|
console.log('skip error', err);
|
||||||
method: 'get'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const post = (id) => {
|
|
||||||
request(
|
|
||||||
'/api',
|
|
||||||
{ id },
|
|
||||||
{
|
|
||||||
responseType: 'blob'
|
|
||||||
}
|
|
||||||
).then((data) => {
|
|
||||||
console.log(data);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
get(1);
|
get(1);
|
||||||
// get(2);
|
|
||||||
// get(3);
|
|
||||||
|
|
||||||
// post(1);
|
|
||||||
// post(2);
|
|
||||||
post(3);
|
|
||||||
|
|
||||||
// setTimeout(() => {
|
|
||||||
// request('/api', null, {
|
|
||||||
// throttle: 3000,
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// }, 1000);
|
|
||||||
|
|
||||||
// setTimeout(() => {
|
|
||||||
// request('/api', null, {
|
|
||||||
// throttle: 3000,
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// throttle: 3000,
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// }, 3200);
|
|
||||||
|
|
||||||
// request('/api', null, {
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
// request('/api', null, {
|
|
||||||
// cache: true
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// request('/api', null, {
|
|
||||||
// // skipErrorHandler: [500]
|
|
||||||
// }).then((res) => {
|
|
||||||
// console.log(res);
|
|
||||||
// }).catch((err) => {
|
|
||||||
// console.log('inner error', err);
|
|
||||||
// });
|
|
||||||
return {
|
return {
|
||||||
fes,
|
fes,
|
||||||
rotate,
|
rotate,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user