// 错误接口信息存到后台数据库  persagy定制

export default function (pobj) {
    const API_BASE_URL = "https://duoduoenv.sagacloud.cn";
  var params = {
    name: pobj.name, // 类型:String  必有字段  备注:接口名字
    type: 2, // 类型:String  必有字段  备注:类型,默认传 2 (表示异常)
    success: false, // 类型:Boolean  必有字段  备注:默认false
    input: pobj.input, // 类型:String  必有字段  备注:请求输入参数
    exception: pobj.exception // 类型:String  必有字段  备注:异常信息
  };
  var info = {
    url: `${API_BASE_URL}/server/systemLog/save`,
    method: 'POST',
    data: JSON.stringify(params)
  };

//   const token = store.state.user.token;
//   if (token) {
//     info.header = Object.assign({
//       token
//     }, info.header)
//   }

  info.timeout = info.timeout || 10 * 1000; // 默认超时为10s

  return new Promise((resolve, reject) => {
    wx.request(
      Object.assign(info, {
        success(res) {
          if (res.statusCode >= 400) {
            console.log(
              `systemLog/save接口请求失败:code=${res.statusCode},msg=${
                res.message || JSON.stringify(res)
              }`
            );
            reject(res.errMsg);
          } else if (res.data.code !== 1 && res.data.code) {
            console.log('systemLog/save请求失败:' + `${res.data.msg}`);
            reject(res.data);
          } else {
            resolve(res.data);
          }
        },
        fail(res) {
          reject({ ...res, reason: 'wxRequestFail' });
          console.log(`微信接口systemLog/save调用失败:${JSON.stringify(res)}`);
        }
      })
    );
  });
}