nishimura.clubnishimura.club

async/awaitのエラーハンドリング

作成日
2021-09-28
更新日
2021-09-28

then()の可動性が高いと思わないので、async/await構文のエラーハンドリングについてまとめる。

実装

基本的には、try ~ catchで、囲む。loading状態の制御などは、finallyに書く。

async function update () { try { this.loading = true; await axios.put("/api/v1/users"); } catch (e) { console.error(e); } finally { this.loading = false; } };

ドキュメント

Related

Tags

JavaScript

Share

Table of Contents