errorRequest.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import config from '@/config';
  2. import store from '@/store';
  3. // 错误接口信息存到后台数据库 persagy定制
  4. export default function (pobj) {
  5. var params = {
  6. name: pobj.name, // 类型:String 必有字段 备注:接口名字
  7. type: 2, // 类型:String 必有字段 备注:类型,默认传 2 (表示异常)
  8. success: false, // 类型:Boolean 必有字段 备注:默认false
  9. input: pobj.input, // 类型:String 必有字段 备注:请求输入参数
  10. exception: pobj.exception // 类型:String 必有字段 备注:异常信息
  11. };
  12. var info = {
  13. url: `${config.brsgServer.duoduoUrl}/server/systemLog/save`,
  14. method: 'POST',
  15. data: JSON.stringify(params)
  16. };
  17. const token = store.state.user.token;
  18. if (token) {
  19. info.header = Object.assign({
  20. token
  21. }, info.header)
  22. }
  23. info.timeout = info.timeout || 10 * 1000; // 默认超时为10s
  24. return new Promise((resolve, reject) => {
  25. wx.request(
  26. Object.assign(info, {
  27. success(res) {
  28. if (res.statusCode >= 400) {
  29. console.log(
  30. `systemLog/save接口请求失败:code=${res.statusCode},msg=${
  31. res.message || JSON.stringify(res)
  32. }`
  33. );
  34. reject(res.errMsg);
  35. } else if (res.data.code !== 1 && res.data.code) {
  36. console.log('请systemLog/save求失败:' + `${res.data.msg}`);
  37. reject(res.data);
  38. } else {
  39. resolve(res.data);
  40. }
  41. },
  42. fail(res) {
  43. reject({ ...res, reason: 'wxRequestFail' });
  44. console.log(`微信接口systemLog/save调用失败:${JSON.stringify(res)}`);
  45. }
  46. })
  47. );
  48. });
  49. }