Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
nuxtjs-axios-error-handling
Search
odanado
PRO
February 03, 2020
Programming
400
0
Share
nuxtjs-axios-error-handling
odanado
PRO
February 03, 2020
More Decks by odanado
See All by odanado
Vitest Browser Mode への期待 / Vitest Browser Mode
odanado
PRO
3
5.5k
@nestjs/bull の活用について
odanado
PRO
0
1.5k
クラウド KMS の活用 / TOKYO BLOCKCHAIN TECH MEETUP 2022
odanado
PRO
0
1.3k
Vue.observable で状態管理 / vue-observable-state-management
odanado
PRO
4
2.1k
ブロックチェーンアプリのトランザクションに対するデータ分析 / PyCon-JP-2019
odanado
PRO
0
460
スマートコントラクトに対する既知の攻撃とその対策 / bc.tokyo-21
odanado
PRO
0
280
最近のweb3.js事情 / bc.tokyo-19
odanado
PRO
2
560
YAPC::Tokyo 2019に スタッフ参加してみて / kichijojipm-18
odanado
PRO
1
2.4k
JavaScript + Dockerの知見 / knowledge-of-docker-in-javascript
odanado
PRO
9
55k
Other Decks in Programming
See All in Programming
ECR拡張スキャンでSBOMを収集して サプライチェーン攻撃の影響調査を 爆速で終わらせてみた
akihisaikeda
1
120
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
5
5.6k
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
3.2k
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
2k
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
2
120
Agentic UI in the Frontend: Architectures with Open Standards @JAX 2026 in Mainz
manfredsteyer
PRO
0
120
SkillsをS3 Filesに置く時のあれこれ
watany
3
1.6k
AWSはOSSをどのように 考えているのか?
akihisaikeda
0
120
Cloudflare で始める Data Platform
ta93abe
0
180
Back to the roots of date
jinroq
0
870
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
390
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
Embracing the Ebb and Flow
colly
88
5k
A Tale of Four Properties
chriscoyier
163
24k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
The browser strikes back
jonoalderson
0
1.1k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
How to make the Groovebox
asonas
2
2.2k
エンジニアに許された特別な時間の終わり
watany
106
240k
Making the Leap to Tech Lead
cromwellryan
135
9.8k
Darren the Foodie - Storyboard
khoart
PRO
3
3.3k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Transcript
@nuxtjs/axios で エラーハンドリング 1 @odan3240
タピオカLT • 初LT (2020年) :tada: 2
自己紹介 • @odan3240 • 株式会社モバイルファクトリー • 最近 ◦ AWS
周り ◦ TypeScript (frontend/backend) ◦ Vue.js 3
@nuxtjs/axios • axios ◦ JavaScript の HTTP クライアントライブラリ •
NuxtJS 向けの axios モジュール ◦ https://github.com/nuxt-community/axios-module 4
エラーハンドリングしたい • API リクエストでエラーが 発生したときにエラーページに飛ばすなどしたい ◦ 公式ドキュメントにあるサンプル ◦ レスポンスが 500
エラーだと /sorry にリダイレクト 5
リダイレクトじゃない挙動にしたい • 例えば ◦ トーストを出す ◦ ページ遷移せずエラーページを表示 • redirect
を呼び出さなければ良い? ◦ NuxtJS のエラーページが表示されてしまう ▪ 内部でエラーがハンドリングされているため ▪ https://github.com/nuxt-community/axios-module/issues/149 6
やりたいこと • 内部のエラーハンドリングをキャンセル • エラーが発生したことを NuxtJS に伝える 7
問題の切り分け • 内部のエラーハンドリングをキャンセル ◦ axios の話 • エラーが発生したことを NuxtJS
に伝える ◦ nuxtjs の話 8
エラーが発生したことを NuxtJS に伝える • NuxtJS の話 • error 関数を呼び出す ◦
https://ja.nuxtjs.org/api/context/ • Nuxt.js と axios のエラーハンドリング周りの話 ◦ https://mya-ake.com/slides/nuxt-axios-error-handling 9
内部のエラーハンドリングをキャンセル • axios でリクエストをキャンセルする方法はあるか? ◦ 「axios promise cancel response」あたりでググる ◦
https://github.com/axios/axios/issues/583 ◦ axios.interceptors.response.use で false を返せば良いっぽい 10
結論 11
まとめ • @nuxtjs/axios で独自のエラーを出す方法を紹介 • 問題を切り分けて立ち向かうの大事 ◦ モジュールの組み合わせで どんどん便利になっている時代なので
• 未解決の issue に解答を示したので 後の人が楽になったはず 12