Problems in the Development of thinkphp5 WeChat Mini Programs

I encountered a problem when using thinkphp5.1x to make WeChat Mini Programs"s payment.
the front-end process is to request the order-issuing API first, and then request the payment interface after the order-issuing API is successful.
Front-end Code:

getpay:function(){
  var token=wx.getStorageSync("token");
  wx.request({
    // 
    url: "http://restcms.cncyz.com/api/v1/placeOrder",
    method:"POST",
    header:{
      token:token
    },
    data:{
      // 
      products:[
        {product_id:1, count:3},
        {product_id:11,count:5}
      ]
    },
    success:function(res){
      console.log(res);
      // 
      wx.request({
        url: "http://restcms.cncyz.com/api/v1/pay",
        method: "POST",
        header: {
          token: token
        },
        data: {
          id: res.data.order_id
        },
        success:function(resn){
          // 
          console.log(resn);
        }
      })
    }
  })
}

the problem encountered is
http://restcms.cncyz.com/api/. order interface threw an exception because the user address does not exist

        $data=UserAddress::where("user_id","=",$this->uid)->find();
        if(empty($data)){
            throw new UserException(["msg"=>""]);
        }
        return $data;

Wechat developer tool

what I don"t understand, the first order exception thrown should be terminated. Why is there a payment error message?
the following code is not supposed to be executed. If an exception is thrown, why will it still be executed? and there is an error message

.
success:function(res){
      console.log(res);
      // 
      wx.request({
        url: "http://restcms.cncyz.com/api/v1/pay",
        method: "POST",
        header: {
          token: token
        },
        data: {
          id: res.data.order_id
        },
        success:function(resn){
          // 
          console.log(resn);
        }
      })
How should the

code be modified? What"s the reason?

Mar.21,2021

the first wx.request () function returns 404, but if you see the printed message successfully, enter the success () callback function.

you can take a look at the wx.request () document. success () is the callback function that received a successful response from the developer's service, while fail () is the callback function that the API call failed.

you should judge whether it is successful in the first success () function

.
  

the backend simplifies the interface to make an interface

Menu