import { Message } from "element-ui";

let request = {};
request = require("./request-base").default;

request.interceptors.request.use(
    config => {
        config.timeout = 10000;
        // console.log("这里可以写自定义的request拦截器");
        return config;
    },
    error => {
        // Do something with request error
        // console.log(error); // for debug
        return Promise.reject(error);
    }
);

request.interceptors.response.use(
    response => {
        // console.log("这里可以写自定义的response拦截器");
        return response
    },
    error => {
        if (error && error.response) {
            const { response } = error;
            const { status, data } = response;
            if (status === 500) {
                // 判断是否是国密异常，进行提示
                if (data && data.statusCode && data.message) {
                    const { statusCode, message } = data;

                    if (statusCode === '406') {
                        Message.error(message);
                    }
                }
            }
        }
        // Do something with request error
        // console.log(error); // for debug
        return Promise.reject(error);
    }
);
export default request;
