【DingTalk Mini Program Development】About Uncaught (in promise) { error : 400 , errorMessage : “ unknown “ } Error reporting

Problem Description

insert image description here

During the development of the DingTalk applet, the internal applets of the enterprise need to use the free login function. See the official document and call the dd.getAuthCode API to obtain the free login authorization code. But there was Uncaught (in promise) { error : 400 , errorMessage : " unknown " }an error .

Original code display

The code provided by DingTalk:
insert image description here
My code:

insert image description here

We copied and pasted the official code verbatim, but we just reported this problem repeatedly, checked it several times, and felt that it was not a problem with the code. The following is the idea and process of solving the bug.

resolution process

Let me talk about the solution found on the Internet first:
add .catch((e) => {}) after the promise, and the error will be solved.

dd.getAuthCode({
    
    
    success:function(res){
    
    
        /*{
            authCode: 'hYLK98jkf0m' //string authCode
        }*/
    },
    fail:function(err){
    
    
    }
}).catch((e)=>{
    
    
	console.log(e);
});

how to say. . . This method is really good, and the console does not report an error, but it doesn't seem to solve the real problem. Because the essential problem is that this api cannot be called normally, and there is no success at all, and it directly jumps to fail. This kind of solution is to throw the error directly. Generally, you don’t need any parameter return value after the request is successful. "Deceive one's ears and steal one's bell". But we need to use the returned free login authorization code here, so obviously we can't "deceive ourselves".

insert image description here

Another way is to say that the interface responds to the problem in the interceptor, but we have not used the request interface, so this solution is not considered.

Let me give you the answer of Kang Yikang GPT:

insert image description here

After the search was fruitless, the form was submitted to the DingTalk work order center, and the staff gave the following solutions:

// index.js里加上:
getAuthCode(){
    
    
 dd.getAuthCode({
    
    
   success:function(res){
    
    
      dd.alert({
    
    
  title: '亲',
  content:'res',
  success: () => {
    
    
  console.info(res)
  },
});

    },
    fail:function(err){
    
    
      dd.alert({
    
    
  title: '亲',
  content: 'err',
  buttonText: '我知道了',
  fail: () => {
    
    
    dd.alert({
    
    
      title: '用户点击了「我知道了」',
    });
  },
});

    }
});
  },

// index.axml加上:
<view>
  <button size="default" type="primary" onTap="getAuthCode">getAuthCode</button>
</view>

insert image description here
Obviously, the code given by the staff is actually similar to the one on the official website, but of course it still fails to solve the problem. Then the staff said that he was not clear either, maybe it was a formatting problem. emmmmm, what a format problem, I almost believed it... Blindly guessing that he might be in a hurry to get off work (after all, it was already 17:53 when he replied to me). . .

insert image description here

Later, I thought that there might be a problem with the configuration step in the process of creating the project, so I asked my partner to recreate the project (fortunately, we haven't started writing this project yet, so don't worry about the workload of rebuilding), but It's a pity that it still hasn't been resolved.

Solution

Last but not least, when I was about to read the DingTalk development documentation all night to fix the bug, my partner said he solved it!
The most ex-bugs often require the simplest solution - the version problem of the DingTalk development tool . . .

insert image description here

This is the version we originally used, and the newer version will report this error. (I really feel that this upgraded version is very difficult to use. Except for these bugs, many functions in it can't be clicked. For example, you can't choose the associated application. Lightning and lightning protection!!!)

insert image description here

The following is the version that can successfully obtain the authorization code without registration. Although it is also the latest version, this version is the latest version of the old version, which is relatively stable. (The old version is still easier to use! But I don't know what bugs will appear...)

insert image description here

The above is the whole process of solving this bug. If there are other or better solutions, please let me know!
If wrong, please correct me!

insert image description here

Guess you like

Origin blog.csdn.net/aDiaoYa_/article/details/129964669