diff --git a/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt b/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt index 2d4a71bb9..cec465ad3 100644 --- a/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt +++ b/mirai-core/src/commonMain/kotlin/network/handler/selector/AbstractKeepAliveNetworkHandlerSelector.kt @@ -76,10 +76,7 @@ internal abstract class AbstractKeepAliveNetworkHandlerSelector= maxAttempts) { - throw IllegalStateException( - "Failed to resume instance. Maximum attempts reached.", - exceptionCollector.getLast() - ) + throw exceptionCollector.getLast() ?: MaxAttemptsReachedException(null) } yield() // Avoid endless recursion. val current = getCurrentInstanceOrNull() diff --git a/mirai-core/src/commonMain/kotlin/network/handler/selector/MaxAttemptsReachedException.kt b/mirai-core/src/commonMain/kotlin/network/handler/selector/MaxAttemptsReachedException.kt new file mode 100644 index 000000000..6d26a6cec --- /dev/null +++ b/mirai-core/src/commonMain/kotlin/network/handler/selector/MaxAttemptsReachedException.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2019-2021 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.internal.network.handler.selector + +internal data class MaxAttemptsReachedException( + override val cause: Throwable? +) : IllegalStateException("Failed to resume instance. Maximum attempts reached.") \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/network/handler/selector/NetworkHandlerSelector.kt b/mirai-core/src/commonMain/kotlin/network/handler/selector/NetworkHandlerSelector.kt index 90d0537c8..3d5d3998f 100644 --- a/mirai-core/src/commonMain/kotlin/network/handler/selector/NetworkHandlerSelector.kt +++ b/mirai-core/src/commonMain/kotlin/network/handler/selector/NetworkHandlerSelector.kt @@ -40,6 +40,7 @@ internal interface NetworkHandlerSelector { * Returned [H] can be in [NetworkHandler.State.OK] only (but it may happen that the state changed just after returning from this function). * * This function may throw exceptions, which would be propagated to the original caller of [SelectorNetworkHandler.resumeConnection]. + * @throws MaxAttemptsReachedException */ suspend fun awaitResumeInstance(): H } \ No newline at end of file