Commit bb06a062d8a3688ab412ffdcd77e511afc3aea76

Authored by wangfan
1 parent 71f63ad0

rollbar

Showing 2 changed files with 47 additions and 40 deletions
@@ -9,40 +9,7 @@ const api_timeout = 2000; //接口超时时间,默认2s @@ -9,40 +9,7 @@ const api_timeout = 2000; //接口超时时间,默认2s
9 import api from './api.url' 9 import api from './api.url'
10 import uri_dc from './uri' 10 import uri_dc from './uri'
11 const server_host = uri_dc.HOST__LINE; 11 const server_host = uri_dc.HOST__LINE;
12 -/**  
13 - * @param data  
14 - * @param status started, succeeded (default), failed, or timed_out  
15 - */  
16 -function rollbar(data) {  
17 - // let raw=JSON.stringify(data)  
18 - // let trace={  
19 - // frames:[data],  
20 - // exception:{class:raw},  
21 - // }  
22 - let param={  
23 - access_token: '83bd2afd09b8402b943cb1894a84ec51',  
24 - data:{  
25 - body:{  
26 - //trace:trace,  
27 - // trace_chain:[trace],  
28 - message:{  
29 - body:data,  
30 - },  
31 - // crash_report:{  
32 - // raw:raw  
33 - // },  
34 - },  
35 - }  
36 - }  
37 - wx.request({  
38 - url: 'https://api.rollbar.com/api/1/item/',  
39 - method: 'POST',  
40 - data: param,  
41 - header: {  
42 - //'content-type': 'application/x-www-form-urlencoded'  
43 - },  
44 - })  
45 -} 12 +import rollbar from './rollbar'
46 /** 13 /**
47 * 14 *
48 * @param act 15 * @param act
@@ -122,11 +89,7 @@ function rpc(host = '', act, data = {}, fouce = false, header = {}, silence = tr @@ -122,11 +89,7 @@ function rpc(host = '', act, data = {}, fouce = false, header = {}, silence = tr
122 cache(cache_key, res.data, cachetime);//.then().catch(); 89 cache(cache_key, res.data, cachetime);//.then().catch();
123 } 90 }
124 if (res.data.ret !== 200) { 91 if (res.data.ret !== 200) {
125 - try {  
126 - res.data.msg = res.data.msg.replace('非法请求:', '');  
127 - } catch (e) {  
128 - console.log('res-fail', res, e);  
129 - } 92 + res.data.msg = res.data.msg.replace('非法请求:', '');
130 } 93 }
131 } 94 }
132 success(res.data); 95 success(res.data);
@@ -137,7 +100,8 @@ function rpc(host = '', act, data = {}, fouce = false, header = {}, silence = tr @@ -137,7 +100,8 @@ function rpc(host = '', act, data = {}, fouce = false, header = {}, silence = tr
137 formids: formids.toString(), 100 formids: formids.toString(),
138 operator: operator, 101 operator: operator,
139 post_data:cache_key, 102 post_data:cache_key,
140 - response:res 103 + response:res,
  104 + catch:JSON.stringify(e),
141 }) 105 })
142 } 106 }
143 107
  1 +/**
  2 + * @param data
  3 + * @param status started, succeeded (default), failed, or timed_out
  4 + */
  5 +function rollbar(data,title='') {
  6 + let pages=getCurrentPages();
  7 + let p=pages[pages.length-1];
  8 + let body_msg=p.route+'?'+JSON.stringify(p.options);
  9 + title=title?title:data.response
  10 + let param={
  11 + access_token: '83bd2afd09b8402b943cb1894a84ec51',
  12 + data:{
  13 + body:{
  14 + message:{
  15 + body:title,
  16 + route: body_msg,
  17 + },
  18 + "request": {
  19 + "method": "POST",
  20 + "headers": {
  21 + // Header names should be formatted like they are in HTTP.
  22 + openid: data.openid,
  23 + formids: data.formids,
  24 + operator: data.operator,
  25 + },
  26 + "body": data.post_data,
  27 + },
  28 + exception:data.exception,
  29 + context:data.response,
  30 + title: title,
  31 + },
  32 + }
  33 + }
  34 + wx.request({
  35 + url: 'https://api.rollbar.com/api/1/item/',
  36 + method: 'POST',
  37 + data: param,
  38 + header: {
  39 + //'content-type': 'application/x-www-form-urlencoded'
  40 + },
  41 + })
  42 +}
  43 +export default rollbar;