rituparna
rituparna

Reputation: 91

expects catch() or return even after returning the result

sorry for asking a silly question but I have returned everything in the the given code but still it says

52:5   error    Expected catch() or return      promise/catch-or-return

I don't know what its expecting.this is my code.

52:5    rp(options).then(function (response,body) {
            a = response.data;
            return a;
        }).catch(function (error) {
            // POST failed...
            return console.log('error');

        }).then(result =>{
           console.log('key: ' + a);
           return db.collection('Users').doc(user_id).set({name:name1,notification_key:a,image:image1,token_id:token_id1,email:token_email});
});

Upvotes: 1

Views: 687

Answers (1)

Daniele
Daniele

Reputation: 892

It's a linter error (eslint rule promise/catch-or-return). It's meant to avoid unhandled rejections and promises.

The problem with line 52 is most likely that the full code is:

function myFunction() {
   /* ... */      
   rp().then(/*.*/).catch(/*.*/).then(/*.*/);
}

You are not handling the promise, so either you add a catch() after the final then or return the whole promise with return rp().

Upvotes: 1

Related Questions