Skip to content

Commit

Permalink
Merge pull request #13 from simple-robot/dev/pref-api-err
Browse files Browse the repository at this point in the history
优化API请求时的异常提示和日志
  • Loading branch information
ForteScarlet authored Jun 9, 2024
2 parents 53f2612 + 35b481d commit 1ee3673
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object P {
override val homepage: String get() = HOMEPAGE


private val baseVersion = v(0, 1, 0)
private val baseVersion = v(0, 1, 1)

val snapshotVersion = baseVersion - Version.SNAPSHOT
override val version = if (isSnapshot()) snapshotVersion else baseVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import love.forte.simbot.logger.Logger
import love.forte.simbot.logger.LoggerFactory
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.jvm.JvmOverloads
import kotlin.jvm.JvmSynthetic

/**
Expand Down Expand Up @@ -64,7 +63,6 @@ public val ApiLogger: Logger = LoggerFactory.getLogger("love.forte.simbot.compon
* @param actionSuffixes 会被拼接到 [OneBotApi.action] 的行为后缀,可参考 [OneBotApi.Actions].
*/
@JvmSynthetic
@JvmOverloads
public suspend fun OneBotApi<*>.request(
client: HttpClient,
host: Url,
Expand Down Expand Up @@ -153,7 +151,6 @@ public suspend fun OneBotApi<*>.request(
* @param actionSuffixes 会被拼接到 [OneBotApi.action] 的行为后缀,可参考 [OneBotApi.Actions].
*/
@JvmSynthetic
@JvmOverloads
public suspend fun OneBotApi<*>.request(
client: HttpClient,
host: String,
Expand All @@ -171,7 +168,6 @@ public suspend fun OneBotApi<*>.request(
*
*/
@JvmSynthetic
@JvmOverloads
public suspend fun OneBotApi<*>.requestRaw(
client: HttpClient,
host: Url,
Expand All @@ -181,17 +177,20 @@ public suspend fun OneBotApi<*>.requestRaw(
): String {
val response = request(client, host, accessToken, actionSuffixes)
val status = response.status
val body = response.bodyAsText(charset)

if (!status.isSuccess()) {
throw OneBotApiResponseNotSuccessException(status)
}
return response.bodyAsText(charset).also { raw ->
ApiLogger.debug(
"API [{}] RES <=== {}, raw: {}",
action,
response.request.url,
raw
)
throw OneBotApiResponseNotSuccessException(status, "status: $status, body: $body")
}

ApiLogger.debug(
"API [{}] RES <=== {}, body: {}",
action,
response.request.url,
body
)

return body
}

/**
Expand All @@ -204,7 +203,6 @@ public suspend fun OneBotApi<*>.requestRaw(
*
*/
@JvmSynthetic
@JvmOverloads
public suspend fun OneBotApi<*>.requestRaw(
client: HttpClient,
host: String,
Expand All @@ -222,7 +220,6 @@ public suspend fun OneBotApi<*>.requestRaw(
* @see OneBotApi.request
*/
@JvmSynthetic
@JvmOverloads
public suspend fun <T : Any> OneBotApi<T>.requestResult(
client: HttpClient,
host: Url,
Expand All @@ -243,7 +240,6 @@ public suspend fun <T : Any> OneBotApi<T>.requestResult(
* @see OneBotApi.request
*/
@JvmSynthetic
@JvmOverloads
public suspend fun <T : Any> OneBotApi<T>.requestResult(
client: HttpClient,
host: String,
Expand All @@ -263,7 +259,6 @@ public suspend fun <T : Any> OneBotApi<T>.requestResult(
* @see OneBotApi.request
*/
@JvmSynthetic
@JvmOverloads
public suspend fun <T : Any> OneBotApi<T>.requestData(
client: HttpClient,
host: Url,
Expand All @@ -286,7 +281,6 @@ public suspend fun <T : Any> OneBotApi<T>.requestData(
* @see OneBotApi.request
*/
@JvmSynthetic
@JvmOverloads
public suspend fun <T : Any> OneBotApi<T>.requestData(
client: HttpClient,
host: String,
Expand Down

0 comments on commit 1ee3673

Please sign in to comment.