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?

処理失敗時にSentryにログを送信する共通処理

Posted at

はじめに

今回はAPI通信など、Kotlin.runchachingでSentryにログを送信する共通処理を紹介していきます

コード

inline fun <T> Result<T>.onFailureWithSentry(action: (exception: Throwable) -> Unit): Result<T> {
    if (isFailure) {
        val exception = exceptionOrNull()!!

        // Sentryに送信すべきエラーかどうかを判定
        if (exception.shouldReportToSentry()) {
            Sentry.captureException(exception)
        }

        // Timberでのログ出力は継続
        Timber.e(exception)

        // 追加の処理を実行
        action(exception)
    }
    return this
}

最後に

Sentry自体扱うのが初めてなので手探りですが、選択肢が増えるのはいいことだと思います

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?