Skip to content

Commit

Permalink
Merge pull request #2085 from Infomaniak/dont-log-access-denied-notif
Browse files Browse the repository at this point in the history
fix: Don't send a Sentry when we have an access_denied APIErrorException
  • Loading branch information
tevincent authored Nov 22, 2024
2 parents e459269 + 7f266bc commit 660c3ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/src/main/java/com/infomaniak/mail/utils/ErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object ErrorCode {

//region Mailbox
const val MAILBOX_LOCKED = "mailbox_locked"
const val ACCESS_DENIED = "access_denied"
const val ERROR_WHILE_LINKING_MAILBOX = "error_while_linking_mailbox"
const val INVALID_MAILBOX_PASSWORD = "invalid_mailbox_password"
//endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class FetchMessagesManager @Inject constructor(

private lateinit var coroutineScope: CoroutineScope

private fun shouldLogToSentry(throwable: Throwable?): Boolean {
return when (throwable) {
is CancellationException, is NetworkException -> false
is ApiErrorException -> throwable.errorCode != ErrorCode.ACCESS_DENIED
else -> true
}
}

// We can arrive here for Mailboxes we did not open yet. That's why we check before doing anything.
suspend fun execute(
scope: CoroutineScope,
Expand Down Expand Up @@ -96,7 +104,7 @@ class FetchMessagesManager @Inject constructor(
).let { (threads, throwable) ->

if (threads == null) {
if (throwable !is CancellationException && throwable !is NetworkException) {
if (shouldLogToSentry(throwable)) {
SentryDebug.sendFailedNotification(
reason = "RefreshThreads failed",
sentryLevel = SentryLevel.ERROR,
Expand Down

0 comments on commit 660c3ba

Please sign in to comment.