Commit ac1f46f4 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

sync

parent 5c414d78
......@@ -5,7 +5,7 @@ export default {
storeNameSpace: 'kim',
headers: () => ({
Authorization:
'1eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjE0MzAzMzI4NzQsImxpZCI6Im91eWFuZ2JveXUifQ.209scGXfvjPj7KgvXhzrI4ciHg6aTDt8LQ1Z2Nw-ZxA',
'eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjE0MzAzMzI4NzQsImxpZCI6Im91eWFuZ2JveXUifQ.209scGXfvjPj7KgvXhzrI4ciHg6aTDt8LQ1Z2Nw-ZxA',
}),
resCodeKey: 'code', // 后台正常返回错误编码
resMessageKey: 'message', // 后台正常返回错误编码
......
......@@ -44,14 +44,17 @@ class HttpRequest {
res => {
// success
this.destroy(url);
if (options.successHandler instanceof Function) {
options.successHandler({ queues: this.queues, res, options });
}
const { data, status } = res;
return { data, status };
},
error => {
// error
this.destroy(url);
if (error.response) {
console.log(error.response);
if (options.errorHandler instanceof Function) {
options.errorHandler({ queues: this.queues, error, options });
}
return Promise.reject(error);
},
......
......@@ -2,6 +2,10 @@ import { notification } from 'antd';
import HttpRequest from './kim-request';
import config from '@/config';
/**
* todo 还需处理国际化
*/
const codeMessage = {
200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。',
......@@ -55,41 +59,48 @@ const axios = new HttpRequest({
* @param {配置项} more
*/
const handleResponse = (response, more) => {
console.log('handleResponse', response);
const { data } = response;
//
if (`${data[resCodeKey]}` !== `${successCode}`) {
if (isThrowError) {
const errorMessage = data[resMessageKey] || '后端接口返回异常';
const error = new Error(data[resCodeKey]);
let error = new Error();
error = { ...error, ...data };
error.code = data[resCodeKey];
error.message = errorMessage;
return Promise.reject(error);
}
}
// success
return data;
};
const handleError = error => {
console.log('handleError');
const { response } = error;
console.log('handleError', response);
// 如果response存在
if (response && response.status) {
// const errorText = codeMessage[response.status] || response.statusText;
// const {
// status,
// config: { url },
// } = response;
console.log('什么情况');
const errorText = codeMessage[response.status] || response.statusText;
const {
status,
config: { url },
} = response;
notification.error({
message: '请求错误 ',
description: '111',
duration: 100,
message: `请求错误 ${status}: ${url}`,
description: errorText,
});
} else {
const { code, message } = error;
notification.error({
key: `notification_${code ? message : code}`,
message: '请求错误',
description: message,
});
}
if (isThrowError) {
throw error;
} else {
return error;
}
};
export default function request(url, options = {}, more = {}) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment