From 5d9d5f73a2ec74316b0acf5d00b466da1637c577 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Wed, 15 Jan 2025 13:31:50 +0100 Subject: [PATCH] chore: Code review --- .../managers/TransferManager.kt | 8 ++++---- .../network/exceptions/DeeplinkException.kt | 17 ++++++++--------- .../network/repositories/TransferRepository.kt | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt index 2379626a..e1bfc744 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt @@ -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, @@ -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, diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/exceptions/DeeplinkException.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/exceptions/DeeplinkException.kt index 847b8801..4c51cc2c 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/exceptions/DeeplinkException.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/exceptions/DeeplinkException.kt @@ -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 { @@ -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 } } diff --git a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/TransferRepository.kt b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/TransferRepository.kt index 53eb467c..51939c3a 100644 --- a/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/TransferRepository.kt +++ b/STNetwork/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/network/repositories/TransferRepository.kt @@ -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 = runCatching { transferRequest.getTransfer(linkUUID, password)