0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Android/Kotlin】並列通信で401エラーになった場合、トークン更新&再通信

Posted at

はじめに

Androidの並列通信で401エラー時にトークン更新&再通信する処理について解説。

前提

通信時、Okhttp3を使用していること。

方法

401エラー検知方法

Authenticator.authenticate()メソッドを使用することにより、401エラー時の処理が記述可能

並列通信時、トークン更新を1回だけにする

  • @Synchronizedアノテーションにより、他通信と同期させる

  • リクエストしたトークンと現在のトークンを比較して、同じだったらトークン更新していないとみなし、トークン更新を行う。異なっていたらすでにトークン更新しているとみなし、再通信を行うようにする

コード

こちらに記載。

参考サイト

公式リファレンス:

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?