エラーオブジェクトが帰ってきた場合に、それを判定して条件分岐させたいのですが、どのような方法がありますか??
js
1 2const hoge = api.huga() 3 4huga(){ 5return foo 6 .get(honya) 7 .catch(err) 8 9
でhogeにerrorが入っていることから条件分岐させて処理したいです。
typeofを使用した場合
下記のような状態になってしまいます
Unhandled Rejection (TypeError): Cannot read property 'status' of undefined Show._callee3$ src/Courses.js:227 224 | const course = await this.props.api.showCourse( 225 | this.props.match.params.courseId 226 | ); > 227 | if (typeof course.response.status !=="undefined") { 228 | this.setState({ isValidUrl: false }); 229 | return; 230 | }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。