Skip to content

Commit

Permalink
chore: Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Jan 15, 2025
1 parent 51fd518 commit 5d9d5f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +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 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 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(
CancellationException::class,
Expand All @@ -182,10 +182,10 @@ class TransferManager internal constructor(
NetworkException::class,
UnknownException::class,
RealmException::class,
PasswordNeededDeeplinkException::class,
WrongPasswordDeeplinkException::class,
ExpiredDeeplinkException::class,
NotFoundDeeplinkException::class,
PasswordNeededDeeplinkException::class,
WrongPasswordDeeplinkException::class,
)
suspend fun addTransferByLinkUUID(
linkUUID: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ package com.infomaniak.multiplatform_swisstransfer.network.exceptions
*/
sealed class DeeplinkException(statusCode: Int, override val message: String) : ApiException(statusCode, message) {

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

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

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

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

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

internal companion object {

Expand All @@ -48,15 +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], [ExpiredDeeplinkException]
* or the original [UnexpectedApiErrorFormatException] if we cannot map it to a [DeeplinkException].
* @return An instance of [DeeplinkException] or the original [UnexpectedApiErrorFormatException]
* if we cannot map it to a [DeeplinkException].
*/
fun UnexpectedApiErrorFormatException.toDeeplinkException() = when {
message?.contains(ERROR_NEED_PASSWORD) == true -> PasswordNeededDeeplinkException()
message?.contains(ERROR_WRONG_PASSWORD) == true -> WrongPasswordDeeplinkException()
message?.contains(ERROR_EXPIRED) == true -> ExpiredDeeplinkException()
statusCode == 404 -> NotFoundDeeplinkException()
message?.contains(ERROR_NEED_PASSWORD) == true -> PasswordNeededDeeplinkException()
message?.contains(ERROR_WRONG_PASSWORD) == true -> WrongPasswordDeeplinkException()
else -> this
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class TransferRepository internal constructor(private val transferRequest: Trans
UnexpectedApiErrorFormatException::class,
NetworkException::class,
UnknownException::class,
PasswordNeededDeeplinkException::class,
WrongPasswordDeeplinkException::class,
ExpiredDeeplinkException::class,
NotFoundDeeplinkException::class,
PasswordNeededDeeplinkException::class,
WrongPasswordDeeplinkException::class,
)
suspend fun getTransferByLinkUUID(linkUUID: String, password: String?): ApiResponse<TransferApi> = runCatching {
transferRequest.getTransfer(linkUUID, password)
Expand Down

0 comments on commit 5d9d5f7

Please sign in to comment.