This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
106 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/main/java/dev/medzik/librepass/android/utils/Exception.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package dev.medzik.librepass.android.utils | ||
|
||
import android.content.Context | ||
import dev.medzik.android.utils.runOnUiThread | ||
import dev.medzik.android.utils.showToast | ||
import dev.medzik.librepass.android.BuildConfig | ||
import dev.medzik.librepass.android.R | ||
import dev.medzik.librepass.client.errors.ApiException | ||
import dev.medzik.librepass.client.errors.ClientException | ||
import dev.medzik.librepass.responses.ResponseError | ||
|
||
/** Log exception if debugging is enabled. */ | ||
fun Exception.debugLog() { | ||
if (BuildConfig.DEBUG) { | ||
printStackTrace() | ||
} | ||
} | ||
|
||
/** Handle exceptions. Show toast with an error message. */ | ||
fun Exception.showErrorToast(context: Context) { | ||
// log exception trace if debugging is enabled | ||
debugLog() | ||
|
||
val message = when (this) { | ||
// // handle encrypt exception | ||
// is EncryptException -> { context.getString(R.string.Error_EncryptionError) } | ||
// handle client exception (network error) | ||
is ClientException -> { context.getString(R.string.Error_NetworkError) } | ||
// handle api exceptions | ||
is ApiException -> { getTranslatedErrorMessage(context) } | ||
// handle other exceptions | ||
else -> { context.getString(R.string.Error_UnknownError) } | ||
} | ||
|
||
runOnUiThread { context.showToast(message) } | ||
} | ||
|
||
fun ApiException.getTranslatedErrorMessage(context: Context): String { | ||
return when (responseError) { | ||
ResponseError.INVALID_CREDENTIALS -> context.getString(R.string.API_Error_INVALID_CREDENTIALS) | ||
ResponseError.RE_LOGIN_REQUIRED -> context.getString(R.string.API_Error_RE_LOGIN_REQUIRED) | ||
ResponseError.EMAIL_NOT_VERIFIED -> context.getString(R.string.API_Error_EMAIL_NOT_VERIFIED) | ||
ResponseError.TOO_MANY_REQUESTS -> context.getString(R.string.API_Error_TOO_MANY_REQUESTS) | ||
ResponseError.DATABASE_DUPLICATED_KEY -> context.getString(R.string.API_Error_DATABASE_DUPLICATED_KEY) | ||
ResponseError.UNEXPECTED_SERVER_ERROR -> context.getString(R.string.API_Error_UNEXPECTED_SERVER_ERROR) | ||
else -> message | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/dev/medzik/librepass/android/utils/KeyAlias.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.medzik.librepass.android.utils | ||
|
||
import dev.medzik.android.crypto.KeyStoreAlias | ||
|
||
enum class KeyAlias : KeyStoreAlias { | ||
BiometricPrivateKey, | ||
DataStoreEncrypted | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
app/src/main/java/dev/medzik/librepass/android/utils/exception/ApiException.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.