Authored by 李奇

接口请求报错上报添加

@@ -415,7 +415,6 @@ App({ @@ -415,7 +415,6 @@ App({
415 }, 415 },
416 416
417 getShareInfo: function () { 417 getShareInfo: function () {
418 - // console.log('getShareInfo');  
419 let param = { 418 let param = {
420 share_id: this.globalData.shareId, 419 share_id: this.globalData.shareId,
421 } 420 }
@@ -29,7 +29,6 @@ let getDeviceInfo = function (app) { @@ -29,7 +29,6 @@ let getDeviceInfo = function (app) {
29 } 29 }
30 } 30 }
31 } 31 }
32 -  
33 return device; 32 return device;
34 } 33 }
35 34
@@ -89,12 +88,7 @@ let appReport = function ({ reportType = 'hb', pt, pn, param = {} } = {}, _this) @@ -89,12 +88,7 @@ let appReport = function ({ reportType = 'hb', pt, pn, param = {} } = {}, _this)
89 }); 88 });
90 }) 89 })
91 }; 90 };
92 - _appReport(APP_REPORT_HOST, parameters)  
93 - .then(function (data) {  
94 - })  
95 - .catch(function (error) {  
96 - });  
97 - 91 + _appReport(APP_REPORT_HOST, parameters);
98 } 92 }
99 93
100 export default appReport; 94 export default appReport;
  1 +import md5 from '../vendors/md5';
1 import Promise from '../vendors/es6-promise'; 2 import Promise from '../vendors/es6-promise';
2 import objectAssign from '../vendors/object-assign'; 3 import objectAssign from '../vendors/object-assign';
3 import trimObject from '../utils/trimObject'; 4 import trimObject from '../utils/trimObject';
4 import queryString from '../vendors/query-string'; 5 import queryString from '../vendors/query-string';
5 -import md5 from '../vendors/md5';  
6 -import {API_HOST,APP_VERSION, CLIENT_TYPE, PRIVATE_KEY} from '../libs/config';  
7 import { getYHStorageSync } from '../utils/util'; 6 import { getYHStorageSync } from '../utils/util';
  7 +import {API_HOST,APP_VERSION, CLIENT_TYPE, PRIVATE_KEY} from '../libs/config';
  8 +import appReport from './appReport';
8 9
9 let crypto = require('./cryptojs/cryptojs.js').Crypto 10 let crypto = require('./cryptojs/cryptojs.js').Crypto
10 let p1SecretKey = "yoho9646yoho9646" 11 let p1SecretKey = "yoho9646yoho9646"
@@ -38,14 +39,12 @@ function getPrivateKey(){ @@ -38,14 +39,12 @@ function getPrivateKey(){
38 method, 39 method,
39 header: header, 40 header: header,
40 success: function (res) { 41 success: function (res) {
41 - // console.log("res:", res)  
42 if (res && res.data && res.data.data && res.data.data.sk) { 42 if (res && res.data && res.data.data && res.data.data.sk) {
43 app.globalData.p2SecretKey = res.data.data.sk; 43 app.globalData.p2SecretKey = res.data.data.sk;
44 wx.setStorage({ 44 wx.setStorage({
45 key: "p2SecretKey", 45 key: "p2SecretKey",
46 data: res.data.data.sk 46 data: res.data.data.sk
47 }); 47 });
48 -  
49 resolve(app.globalData.p2SecretKey) 48 resolve(app.globalData.p2SecretKey)
50 } 49 }
51 }, 50 },
@@ -54,7 +53,6 @@ function getPrivateKey(){ @@ -54,7 +53,6 @@ function getPrivateKey(){
54 let message = err.message ? err.message : ''; 53 let message = err.message ? err.message : '';
55 let isPrivatekeyError = true 54 let isPrivatekeyError = true
56 reject({ code, message, isPrivatekeyError}); 55 reject({ code, message, isPrivatekeyError});
57 - // console.log("err:",err)  
58 } 56 }
59 }); 57 });
60 58
@@ -127,6 +125,17 @@ function request(method = 'GET') { @@ -127,6 +125,17 @@ function request(method = 'GET') {
127 errMsg = res.errMsg, 125 errMsg = res.errMsg,
128 data = res.data; 126 data = res.data;
129 127
  128 + if (statusCode !== 200) {
  129 + appReport({
  130 + pt: 'NETWORK',
  131 + pn: 'NETWORK_API_CODE_ERR',
  132 + param: {
  133 + url: url,
  134 + ec: statusCode
  135 + }
  136 + });
  137 + }
  138 +
130 if (statusCode == 200) { 139 if (statusCode == 200) {
131 resolve(data); 140 resolve(data);
132 } else { 141 } else {
@@ -143,16 +152,14 @@ function request(method = 'GET') { @@ -143,16 +152,14 @@ function request(method = 'GET') {
143 } 152 }
144 }, 153 },
145 fail: function (err) { 154 fail: function (err) {
146 - let code = err.code ? err.code : 800;  
147 - let message = err.message ? err.message : '';  
148 - if(code === 503) {  
149 - wx.showToast({  
150 - title: '目前参与人数过多请下拉刷新',  
151 - icon: 'none',  
152 - duration: 2000  
153 - }); 155 + appReport({
  156 + pt: 'NETWORK',
  157 + pn: 'NETWORK_API_CODE_ERR',
  158 + param: {
  159 + url: url,
  160 + st: JSON.stringify(err || {})
154 } 161 }
155 - reject({code, message}); 162 + });
156 } 163 }
157 }); 164 });
158 }) 165 })
@@ -218,6 +225,17 @@ function request(method = 'GET') { @@ -218,6 +225,17 @@ function request(method = 'GET') {
218 errMsg = res.errMsg, 225 errMsg = res.errMsg,
219 data = res.data; 226 data = res.data;
220 227
  228 + if (statusCode !== 200) {
  229 + appReport({
  230 + pt: 'NETWORK',
  231 + pn: 'NETWORK_API_CODE_ERR',
  232 + param: {
  233 + url: url,
  234 + ec: statusCode
  235 + }
  236 + });
  237 + }
  238 +
221 if (statusCode == 200) { 239 if (statusCode == 200) {
222 resolve(data); 240 resolve(data);
223 } else { 241 } else {
@@ -234,16 +252,14 @@ function request(method = 'GET') { @@ -234,16 +252,14 @@ function request(method = 'GET') {
234 } 252 }
235 }, 253 },
236 fail: function (err) { 254 fail: function (err) {
237 - let code = err.code ? err.code : 800;  
238 - let message = err.message ? err.message : '';  
239 - if(code === 503){  
240 - wx.showToast({  
241 - title: '目前参与人数过多请下拉刷新',  
242 - icon: 'none',  
243 - duration: 2000  
244 - }); 255 + appReport({
  256 + pt: 'NETWORK',
  257 + pn: 'NETWORK_API_CODE_ERR',
  258 + param: {
  259 + url: url,
  260 + st: JSON.stringify(err || {})
245 } 261 }
246 - reject({ code, message }); 262 + });
247 } 263 }
248 }); 264 });
249 }) 265 })
@@ -271,26 +287,6 @@ function uploadLogData(method = 'POST') { @@ -271,26 +287,6 @@ function uploadLogData(method = 'POST') {
271 } 287 }
272 } 288 }
273 289
274 -function appReport(method = 'POST') {  
275 - return function (url, params = {}) {  
276 - return new Promise(function (resolve, reject) {  
277 - let app = getApp();  
278 - let data = JSON.stringify(params)  
279 - let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';  
280 - let header = {  
281 - 'content-type': "application/json",  
282 - 'x-yoho-sid': md5(sid),  
283 - }  
284 - wx.request({  
285 - url,  
286 - data,  
287 - method,  
288 - header,  
289 - });  
290 - })  
291 - }  
292 -}  
293 -  
294 function _publicParams() { 290 function _publicParams() {
295 let app_version = APP_VERSION; 291 let app_version = APP_VERSION;
296 let os_version = ''; 292 let os_version = '';
@@ -307,14 +303,6 @@ function _publicParams() { @@ -307,14 +303,6 @@ function _publicParams() {
307 // Do something when catch error 303 // Do something when catch error
308 } 304 }
309 305
310 - // app_version = '5.6.0';  
311 - // os_version = '10.3';  
312 - // screen_size = '320x568';  
313 - // let uid = '0';  
314 - // let udid = 'acea1c6170ecca417c67979a406156950bcf4fe5';  
315 - // let physical_channel = 1;  
316 -  
317 -  
318 return { 306 return {
319 app_version, 307 app_version,
320 os_version, 308 os_version,
@@ -402,12 +390,10 @@ export const GET = request('GET'); @@ -402,12 +390,10 @@ export const GET = request('GET');
402 export const POST = request('POST'); 390 export const POST = request('POST');
403 export const PUT = request('PUT'); 391 export const PUT = request('PUT');
404 export const DELETE = request('DELETE'); 392 export const DELETE = request('DELETE');
405 -export const UPLOAD_LOG = uploadLogData('POST')  
406 -export const APP_REPORT = appReport('POST') 393 +export const UPLOAD_LOG = uploadLogData('POST');
407 394
408 module.exports = { 395 module.exports = {
409 sign_body, 396 sign_body,
410 - APP_REPORT,  
411 UPLOAD_LOG, 397 UPLOAD_LOG,
412 GET, 398 GET,
413 POST, 399 POST,