Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update deeplink exception to handle expired deeplinks #148

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ class TransferManager internal constructor(
* @throws NetworkException If there is a network issue during the transfer retrieval.
* @throws UnknownException Any error not already handled by the above ones.
* @throws RealmException An error has occurred with realm database
* @throws ExpiredDeeplinkException If the transfer added via a deeplink is expired
* @throws NotFoundDeeplinkException If the transfer added via a deeplink doesn't exist
* @throws PasswordNeededDeeplinkException If the transfer added via a deeplink is protected by a password
* @throws WrongPasswordDeeplinkException If we entered a wrong password for a deeplink transfer
* @throws NotFoundDeeplinkException If the transfer added via a deeplink is expired or doesn't exist
*/
@Throws(
CancellationException::class,
Expand All @@ -181,9 +182,10 @@ class TransferManager internal constructor(
NetworkException::class,
UnknownException::class,
RealmException::class,
ExpiredDeeplinkException::class,
NotFoundDeeplinkException::class,
PasswordNeededDeeplinkException::class,
WrongPasswordDeeplinkException::class,
NotFoundDeeplinkException::class,
)
suspend fun addTransferByLinkUUID(
linkUUID: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ package com.infomaniak.multiplatform_swisstransfer.network.exceptions
*/
sealed class DeeplinkException(statusCode: Int, override val message: String) : ApiException(statusCode, message) {

class ExpiredDeeplinkException : DeeplinkException(404, "Transfer expired")

class NotFoundDeeplinkException : DeeplinkException(404, "Transfer not found")

class PasswordNeededDeeplinkException : DeeplinkException(401, "Transfer need a password")

class WrongPasswordDeeplinkException : DeeplinkException(401, "Wrong password for this Transfer")

class NotFoundDeeplinkException : DeeplinkException(404, "Transfer is not found")

internal companion object {


private const val ERROR_EXPIRED = "expired"
private const val ERROR_NEED_PASSWORD = "need_password"
private const val ERROR_WRONG_PASSWORD = "wrong_password"

Expand All @@ -45,14 +48,14 @@ sealed class DeeplinkException(statusCode: Int, override val message: String) :
* [DeeplinkException] based on its error message.
*
* @receiver An instance of [UnexpectedApiErrorFormatException].
* @return An instance of [DeeplinkException] which can be [PasswordNeededDeeplinkException],
* [WrongPasswordDeeplinkException], [NotFoundDeeplinkException] or the original [UnexpectedApiErrorFormatException]
* @return An instance of [DeeplinkException] or the original [UnexpectedApiErrorFormatException]
* if we cannot map it to a [DeeplinkException].
*/
fun UnexpectedApiErrorFormatException.toDeeplinkException() = when {
message?.contains(ERROR_EXPIRED) == true -> ExpiredDeeplinkException()
statusCode == 404 -> NotFoundDeeplinkException()
message?.contains(ERROR_NEED_PASSWORD) == true -> PasswordNeededDeeplinkException()
message?.contains(ERROR_WRONG_PASSWORD) == true -> WrongPasswordDeeplinkException()
statusCode == 404 -> NotFoundDeeplinkException()
else -> this
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ class TransferRepository internal constructor(private val transferRequest: Trans
UnexpectedApiErrorFormatException::class,
NetworkException::class,
UnknownException::class,
ExpiredDeeplinkException::class,
NotFoundDeeplinkException::class,
PasswordNeededDeeplinkException::class,
WrongPasswordDeeplinkException::class,
NotFoundDeeplinkException::class,
)
suspend fun getTransferByLinkUUID(linkUUID: String, password: String?): ApiResponse<TransferApi> = runCatching {
transferRequest.getTransfer(linkUUID, password)
Expand Down
Loading