はじめに
今回は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自体扱うのが初めてなので手探りですが、選択肢が増えるのはいいことだと思います