How to reject in async/await syntax?

后端 未结 7 1769
无人及你
无人及你 2020-11-28 17:56

How can I reject a promise that returned by an async/await function?

e.g. Originally:

         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 18:22

    It should probably also be mentioned that you can simply chain a catch() function after the call of your async operation because under the hood still a promise is returned.

    await foo().catch(error => console.log(error));
    

    This way you can avoid the try/catch syntax if you do not like it.

提交回复
热议问题