未处理的拒绝TypeError:无法读取未定义的属性'error_description'

时间:2018-10-18 22:52:29

标签: javascript node.js es6-promise

所以我有一个函数,该函数接受一些JSON对象并返回iamge url和的数组。代码如下。 GetProductImagelinks函数在其他任何地方都可以正常工作,但在这里不行。它返回未处理的拒绝TypeError:无法读取未定义的属性'error_description'。

request.get(shopRequestUrl, { headers: shopRequestHeaders 
}).then((shopResponse) => {
            const paresedResponse = JSON.parse(shopResponse) 
            console.log(typeof paresedResponse)
            //res.status(200).end(shopResponse);
           if(paresedResponse != null){
            ids = ["12390989324","1231231232", "012231231"]
            search.GetProductImageLinks(paresedResponse, ids,(result)=>{
              res.send(result)
            })
           }
       }).catch((error) => {      
           res.status(error.statusCode).send(error.error.error_description);
        });

功能代码如下:

GetProductImageLinks: (RawProductJson, ListOfProdIds, callback) => {
    let imageLinkArray = []
    for(let i = 0; i < ListOfProdIds.length; i++){
        for(let j = 0; j < RawProductJson.products.length;j++){
            list.products[j].images.forEach(image => {
              if(ListOfProdIds[i] == image.product_id){
                  imageLinkArray.push({"product_id": image.product_id, 
            "image_src": image.src, "varrient_id":image.variant_ids})
              }
             });
       }
   }
     callback(imageLinkArray)
   }
}

0 个答案:

没有答案