search

Home  >  Q&A  >  body text

javascript - promise handling exception in express

sms_code(userInfo).then(function(data){
    return res.json(data);
})
.then(function(data){
    return res.json(data);
})
.catch(next);

Why

catch(function(err){
    next(err)
})

can be abbreviated to

.catch(next);
怪我咯怪我咯2783 days ago449

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:27:13

    catch(function(err){
        next(err)
    })
    

    equals

    catch(next)
    
    function next(err){
    
    }

    Do you think it’s okay?

    reply
    0
  • 阿神

    阿神2017-05-16 13:27:13

    setTimeout(function(){
        doSomeSth()
    },1000)
    
    setTimeout(doSomeSth,1000);
    
    

    reply
    0
  • Cancelreply