In wechat applets, the main interface function for interaction with the background server is wx.request(), which is used to initiate HTTPS network requests. Its importance is self-evident. Wx. Request request failed. Wx. Request failed.

  • Wx. Request failed | WeChat open community
  • Wx. request Request failed – SegmentFault No
  • Applet Some models applet users cannot initiate Wx. request, network error…
  • Wx.request () fails. Request :fail. Wechat small program development
  • Request: Fail Collection (various Request: Fail questions)
  • Wx. Request: Fail error screening

Some things happen during development, some things happen after the product launches. The online situation is much more complex than during development and testing, and the reasons for failure can vary. Since testing is not 100% guaranteed to go live, the only thing we have to do is discover and respond quickly.

Wechat small program operation and Maintenance Center provides error logging, but its functions are still limited. Only simple statistics and error display function, and often only by reporting error information is not clear understanding of the cause of the error. This is where powerful third-party monitoring services are necessary.

Small program Demo

To demonstrate this, we use an app called Weik-v2ex developed by Jectychen. V2ex data API basically uses the methods encapsulated in Samuel1112’s repository v2er.

Its running effect is as follows:

There should have been a head on the far left, but it probably didn’t show up for anti-theft reasons.

Sometimes a wechat mini program may use multiple third-party services to fetch data from multiple domain names. Two situations are worth noting:

  • When some interfaces are updated without timely push notifications, the invocation of the interface will fail.
  • The service is not stable, and the return of the interface is very slow at certain times;
  • The interface fails because some terminal user data is inconsistent. Procedure

Therefore, it is necessary to monitor the invocation of the interface after the product goes live.

Access to the monitoring

Fundebug’s micro program error monitoring plug-in supports monitoring HTTP request errors:

  • When the statusCode returned by a request is not 2xx or the fail callback is triggered, Fundebug’s applets monitor plug-in catches the error and sends it to the server.
  • If the interface request takes too long, you can also configure ithttpTimeoutTo monitor.

To use Fundebug monitoring, you need to go to the Fundebug website to register an account and create a wechat mini program monitoring project, and then follow the prompts to access the plug-in. You need to download the JS script for wechat applet monitoring and put it into your own project, then import and use fundebug.init() function to do the necessary configuration.

var fundebug = require(". / utils/fundebug. 1.3.1. Min. Js. "");
fundebug.init({
    apikey: "YOUR-API-KEY".monitorHttpData: true.httpTimeout: 2000.monitorMethodCall: true.monitorMethodArguments: true.setSystemInfo: true.setUserInfo: true.setLocation: true
});
Copy the code

By default, the plugin monitors HTTP request errors and reports Header information. No configuration is required. To facilitate debugging, we configure monitorHttpData to record information in the body section. We set httpTimeout to 2000 milliseconds, after which requests will be reported to the server.

Request: fail error

In order to demonstrate that wx.request returns request:fail, I purposely fixed HOST_URI in utils/api.js.

var HOST_URI = 'https://www.w2ex.com/api/';

Then save and run. Fundebug receives a reported error, the request takes 7072 milliseconds, and returns the request failed.

The running process of the entire applet can be more clearly understood by user behavior:

404 error

This time, I’ll get the interface for the latest topic and make a little change, deliberately writing latest as lastest:

var LATEST_TOPIC = 'topics/lastest.json';

Save and run. Fundebug catches the error and reports it to the server:

Parameter error

When you get the details of a topic, you should pass in the corresponding ID. If the ID is null, undefined, or originally a number we pass in a string and see what happens.

The following figure shows that when we set the parameter ID to undefined, the interface returns 404. And returns a message:

{
    "message": "Object Not Found"."status": "error"
}
Copy the code

About Fundebug

Fundebug focuses on real-time BUG monitoring for JavaScript, wechat applets, wechat games, Alipay applets, React Native, Node.js and Java online applications. Since its official launch on November 11, 2016, Fundebug has handled over 1 billion error events in total, and paid customers include Sunshine Insurance, Walnut Programming, Lychee FM, Zhangmen 1-to-1, Weimai, Qingtuanshe and many other brand enterprises. Welcome to try it for free!

Copyright statement

Reprint please indicate the author Fundebug and this article addresses: blog.fundebug.com/2019/07/01/…