Skip to content

Commit b546bd6

Browse files
authored
Merge pull request #188 from code-payments/chore/bugsnag-notify-in-more-scenarios
chore: notify bugsnag of any errors in more scenarios
2 parents 1a87307 + feb73d3 commit b546bd6

9 files changed

Lines changed: 43 additions & 11 deletions

File tree

api/build.gradle.kts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.cli.common.toBooleanLenient
12
import java.util.Properties
23

34
plugins {
@@ -8,21 +9,32 @@ plugins {
89
}
910

1011
android {
11-
namespace = "com.getcode.api"
12+
namespace = "${Android.namespace}.api"
1213
compileSdk = Android.compileSdkVersion
1314
defaultConfig {
1415
minSdk = Android.minSdkVersion
1516
targetSdk = Android.targetSdkVersion
1617
buildToolsVersion = Android.buildToolsVersion
1718
testInstrumentationRunner = Android.testInstrumentationRunner
1819

20+
buildConfigField("Boolean", "NOTIFY_ERRORS", "false")
21+
1922
javaCompileOptions {
2023
annotationProcessorOptions {
2124
arguments += mapOf("room.schemaLocation" to "$projectDir/schemas")
2225
}
2326
}
2427
}
2528

29+
buildTypes {
30+
getByName("release") {
31+
buildConfigField("Boolean", "NOTIFY_ERRORS", "true")
32+
}
33+
getByName("debug") {
34+
buildConfigField("Boolean", "NOTIFY_ERRORS", (System.getenv("NOTIFY_ERRORS").toBooleanLenient() ?: false).toString())
35+
}
36+
}
37+
2638
java {
2739
toolchain {
2840
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
)
@@ -686,11 +686,12 @@ class HomeViewModel @Inject constructor(
686686
delay(1.seconds)
687687
cancelPayment(false)
688688
}.onFailure { error ->
689-
error.printStackTrace()
690689
TopBarManager.showMessage(
691690
resources.getString(R.string.error_title_payment_failed),
692691
resources.getString(R.string.error_description_payment_failed),
693692
)
693+
694+
ErrorUtils.handleError(error)
694695
uiFlow.update { uiModel ->
695696
uiModel.copy(
696697
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

scripts/internal-testing-build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
date="$(date '+%m.%d.%y')"
4+
5+
export NOTIFY_ERRORS=true
6+
./gradlew assembleDebug
7+
8+
outputDir="$(pwd)/app/build/outputs/apk/debug"
9+
mv "${outputDir}/app-debug.apk" "${outputDir}/app-${date}-debug.apk"
10+
11+
unset NOTIFY_ERRORS

0 commit comments

Comments
 (0)