Moves the exceptions to our own signing exceptions

This commit is contained in:
Vitor Pamplona
2025-08-01 16:09:29 -04:00
parent 26cadfee88
commit 6b946a57c2
3 changed files with 7 additions and 8 deletions

View File

@@ -38,11 +38,10 @@ class NostrSignerInternal(
inline fun <T> runWrapErrors(action: () -> T): T = inline fun <T> runWrapErrors(action: () -> T): T =
try { try {
action() action()
} catch (e: SignerExceptions) {
throw e
} catch (e: Exception) { } catch (e: Exception) {
if (e is CancellationException) throw e if (e is CancellationException) throw e
throw SignerExceptions.CouldNotPerformException("Could not sign event.", e) if (e is SignerExceptions) throw e
throw SignerExceptions.CouldNotPerformException("Could not perform the operation", e)
} }
override suspend fun <T : Event> sign( override suspend fun <T : Event> sign(

View File

@@ -62,7 +62,7 @@ abstract class DecryptCache<I : Any, T : Any>(
// User has did not reply to the approval request. Ignore until later time. // User has did not reply to the approval request. Ignore until later time.
cache = CacheResults.CanTryAgain<T>(TimeUtils.tenSecondsFromNow()) cache = CacheResults.CanTryAgain<T>(TimeUtils.tenSecondsFromNow())
} catch (e: SignerExceptions.CouldNotPerformException) { } catch (e: SignerExceptions.CouldNotPerformException) {
Log.w("DecryptCache", "CouldNotPerformException", e) // Log.w("DecryptCache", "CouldNotPerformException", e)
// Decryption failed. This key might not be able to decrypt anything. Don't try again. // Decryption failed. This key might not be able to decrypt anything. Don't try again.
cache = CacheResults.DontTryAgain<T>() cache = CacheResults.DontTryAgain<T>()
} catch (e: SignerExceptions.SignerNotFoundException) { } catch (e: SignerExceptions.SignerNotFoundException) {

View File

@@ -101,7 +101,7 @@ class PrivateZapRequestBuilder {
event.createdAt, event.createdAt,
) )
} else { } else {
throw IllegalArgumentException("Couldn't find a secret to use. The private zap is neither a post nor an author zap") throw SignerExceptions.CouldNotPerformException("Couldn't find a secret to use. The private zap is neither a post nor an author zap")
} }
try { try {
@@ -112,13 +112,13 @@ class PrivateZapRequestBuilder {
// the sender is logged in. // the sender is logged in.
decryptAnonTag(event.getAnonTag(), myPrivateKeyForThisEvent, altPubkeyToUse) decryptAnonTag(event.getAnonTag(), myPrivateKeyForThisEvent, altPubkeyToUse)
} else { } else {
throw IllegalArgumentException("This private zap cannot be decrypted by this key.") throw SignerExceptions.CouldNotPerformException("This private zap cannot be decrypted by this key.")
} }
} else { } else {
throw IllegalArgumentException("Recipient pubkey not found.") throw SignerExceptions.CouldNotPerformException("Recipient pubkey not found.")
} }
} catch (e: Exception) { } catch (e: Exception) {
throw IllegalArgumentException("Failed to create pubkey for ZapRequest ${event.id}. ${e.message}") throw SignerExceptions.CouldNotPerformException("Failed to create pubkey for ZapRequest ${event.id}. ${e.message}")
} }
} }