Browse Source

handle promise rejection

k.niemeskern 2 years ago
parent
commit
d8e1f746bd
2 changed files with 6 additions and 4 deletions
  1. 5 4
      index.js
  2. 1 0
      lib/API.js

+ 5 - 4
index.js

@@ -29,7 +29,9 @@ async function watchLinkedin(){
     if (info.active){
 
         try {
-            API.getCompanyFollowers(info).then( (followersNb) => {
+            const getFollowers = API.getCompanyFollowers(info)
+            
+            getFollowers.then( (followersNb) => {
 
                 if (followersNb.firstDegreeSize) {
                     info.followers = followersNb.firstDegreeSize
@@ -37,9 +39,8 @@ async function watchLinkedin(){
                     // cleanUp error
                     info.error = 0
                 }
-            }).catch( (err)=> {
-                return new Error(err)
-            })
+            }).catch( err => new Error(err));
+            
         } catch (error) {
             console.log("[DEBUG-LOG][watchLinkedin ERROR]", err);
             info.error++

+ 1 - 0
lib/API.js

@@ -34,6 +34,7 @@ class API {
             };
 
             request.get({ url: url, headers: headers }, (err, response, body) => {
+                console.log(body);
                 if(err || body.status !== 200) {
                     console.log("besoin de reject");
                     return reject(err);