Skip to content

Commit 6efe112

Browse files
committed
chore: notify bugsnag of any errors in more scenarios
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 0001e4a commit 6efe112

8 files changed

Lines changed: 31 additions & 11 deletions

File tree

api/build.gradle.kts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,32 @@ plugins {
88
}
99

1010
android {
11-
namespace = "com.getcode.api"
11+
namespace = "${Android.namespace}.api"
1212
compileSdk = Android.compileSdkVersion
1313
defaultConfig {
1414
minSdk = Android.minSdkVersion
1515
targetSdk = Android.targetSdkVersion
1616
buildToolsVersion = Android.buildToolsVersion
1717
testInstrumentationRunner = Android.testInstrumentationRunner
1818

19+
buildConfigField("Boolean", "NOTIFY_ERRORS", "false")
20+
1921
javaCompileOptions {
2022
annotationProcessorOptions {
2123
arguments += mapOf("room.schemaLocation" to "$projectDir/schemas")
2224
}
2325
}
2426
}
2527

28+
buildTypes {
29+
getByName("release") {
30+
buildConfigField("Boolean", "NOTIFY_ERRORS", "true")
31+
}
32+
getByName("debug") {
33+
buildConfigField("Boolean", "NOTIFY_ERRORS", "false")
34+
}
35+
}
36+
2637
java {
2738
toolchain {
2839
languageVersion.set(JavaLanguageVersion.of(17))

api/src/main/java/com/getcode/network/repository/MessagingRepository.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ class MessagingRepository @Inject constructor(
285285
}: result: ${it.result}"
286286
)
287287
}.onFailure {
288+
ErrorUtils.handleError(it)
288289
Timber.e(t = it, message = "Failed to send rendezvous message.")
289290
}
290291
}

api/src/main/java/com/getcode/network/repository/PaymentRepository.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.getcode.network.client.establishRelationship
1414
import com.getcode.network.client.fetchLimits
1515
import com.getcode.network.client.transferWithResult
1616
import com.getcode.network.exchange.Exchange
17+
import com.getcode.utils.ErrorUtils
1718
import dagger.hilt.android.qualifiers.ApplicationContext
1819
import io.reactivex.rxjava3.core.Completable
1920
import kotlinx.coroutines.CoroutineScope
@@ -48,7 +49,7 @@ class PaymentRepository @Inject constructor(
4849

4950
codeScanned(payload.rendezvous)
5051
return payload to loginAttempt
51-
}.getOrNull()
52+
}.onFailure { ErrorUtils.handleError(it) }.getOrNull()
5253
}
5354

5455
suspend fun rejectLogin(rendezvousKey: KeyPair) {
@@ -174,6 +175,7 @@ class PaymentRepository @Inject constructor(
174175
amount = paymentAmount,
175176
successful = false
176177
)
178+
ErrorUtils.handleError(error)
177179
cont.resumeWithException(error)
178180
}
179181
}

api/src/main/java/com/getcode/utils/ErrorUtils.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ object ErrorUtils {
3939
}
4040

4141
if (
42-
!BuildConfig.DEBUG &&
42+
BuildConfig.NOTIFY_ERRORS &&
4343
throwable !is UnknownHostException &&
4444
throwable !is TimeoutException &&
4545
throwable !is ConnectException
@@ -49,16 +49,18 @@ object ErrorUtils {
4949
}
5050
}
5151

52-
fun isNetworkError(throwable: Throwable): Boolean =
52+
private fun isNetworkError(throwable: Throwable): Boolean =
5353
throwable is TimeoutException ||
5454
throwable.cause is TimeoutException ||
5555
throwable is UnknownHostException ||
5656
throwable.cause is UnknownHostException
5757

58-
fun isRuntimeError(throwable: Throwable): Boolean =
58+
private fun isRuntimeError(throwable: Throwable): Boolean =
5959
throwable is StatusRuntimeException ||
6060
throwable.cause is StatusRuntimeException
6161

62-
fun isSuppressibleError(throwable: Throwable): Boolean =
63-
throwable is SQLException || throwable is net.sqlcipher.SQLException
64-
}
62+
private fun isSuppressibleError(throwable: Throwable): Boolean =
63+
throwable is SQLException || throwable is net.sqlcipher.SQLException || throwable is SuppressibleException
64+
}
65+
66+
data class SuppressibleException(override val message: String): Throwable(message)

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ android {
3535
val properties = Properties()
3636
properties.load(propertiesFile.inputStream())
3737
buildConfigField("String", "MIXPANEL_API_KEY", "\"${properties.getProperty("MIXPANEL_API_KEY")}\"")
38+
buildConfigField("Boolean", "NOTIFY_ERRORS", "false")
3839
}
3940

4041
signingConfigs {

app/src/main/java/com/getcode/models/DeepLinkPaymentRequest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.getcode.model.CurrencyCode
44
import com.getcode.model.Fiat
55
import com.getcode.network.repository.decodeBase64
66
import com.getcode.solana.keys.PublicKey
7+
import com.getcode.utils.ErrorUtils
78
import com.getcode.vendor.Base58
89
import kotlinx.serialization.SerialName
910
import kotlinx.serialization.Serializable
@@ -75,6 +76,7 @@ data class DeepLinkPaymentRequest(
7576
val destination = runCatching { PublicKey.fromBase58(destinationString) }
7677
.getOrNull()
7778
if (destination == null) {
79+
ErrorUtils.handleError(Throwable())
7880
Timber.e("Invalid destination address")
7981
return null
8082
}

app/src/main/java/com/getcode/view/main/home/HomeViewModel.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class HomeViewModel @Inject constructor(
218218
historyController.fetchChats()
219219
},
220220
onFailure = {
221-
Timber.e(t = it, message = "Auto airdrop failed")
221+
ErrorUtils.handleError(it)
222222
prefRepository.set(PrefsBool.IS_ELIGIBLE_GET_FIRST_KIN_AIRDROP, false)
223223
}
224224
)
@@ -688,11 +688,12 @@ class HomeViewModel @Inject constructor(
688688
delay(1.seconds)
689689
cancelPayment(false)
690690
}.onFailure { error ->
691-
error.printStackTrace()
692691
TopBarManager.showMessage(
693692
resources.getString(R.string.error_title_payment_failed),
694693
resources.getString(R.string.error_description_payment_failed),
695694
)
695+
696+
ErrorUtils.handleError(error)
696697
uiFlow.update { uiModel ->
697698
uiModel.copy(
698699
presentationStyle = PresentationStyle.Hidden,

ed25519/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
android {
6-
namespace = "com.getcode.ed25519"
6+
namespace = "${Android.namespace}.ed25519"
77
compileSdk = Android.compileSdkVersion
88
defaultConfig {
99
minSdk = Android.minSdkVersion

0 commit comments

Comments
 (0)