import { message } from 'antd';
import type { RequestConfig } from 'umi';

export const request: RequestConfig = {
  timeout: 10000,
  // other axios options you want
  errorConfig: {
    errorHandler(){
    },
    errorThrower(){
    }
  },
  requestInterceptors: [
    (url, options) => {
      const baseUrl = process.env.NODE_ENV === 'production' ? '' : '/api'//'http://ab.dev.jbpm.shalu.com' // https://edesign.shalu.com'
      // const enterpriseCode = sessionStorage.getItem('enterpriseCode');
      const token = localStorage.getItem('token_a');
 
      if(token) {
        if(!options.headers) {
          options.headers = {}
        }
        options.headers.Authorization = token
      }

      return {
        url: baseUrl + url,
        options
      }
    }
  ],
  responseInterceptors: [
    (response) => {
      const {data = {} as any, config} = response;
      if(data?.error) {
        message.error(data.error);
        return Promise.reject(data.error);
      }
      
      return response;
    }
  ]
};