Skip to content

Commit

Permalink
fix: login status exception
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Nov 13, 2021
1 parent 0eabb72 commit c4a3a16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/main/kotlin/xyz/cssxsh/mirai/plugin/WeiboSubscriber.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ abstract class WeiboSubscriber<K : Comparable<K>>(val type: String) :
info?.copy(last = blog.created)
}
}
} catch (e: Throwable) {
if (e is SerializationException) {
logger.warning({ "$type(${id})监听任务序列化时失败" }, e)
LoginContact?.sendMessage("$type(${id})监听任务序列化时失败, $e")
} catch (exception: Throwable) {
if (exception is SerializationException) {
logger.warning({ "$type(${id})监听任务序列化时失败" }, exception)
LoginContact?.sendMessage("$type(${id})监听任务序列化时失败, $exception")
continue
}

if (client.info.uid != 0L) {
logger.warning { "$type(${id})监听任务执行失败, ${e},尝试重新加载Cookie" }
if ("<html>" in exception.message.orEmpty()) {
logger.warning { "$type(${id})监听任务执行失败, ${exception},尝试重新加载Cookie" }
try {
client.restore()
} catch (cause: Throwable) {
Expand All @@ -147,7 +147,7 @@ abstract class WeiboSubscriber<K : Comparable<K>>(val type: String) :
}
} else {
LoginContact?.sendMessage("WEIBO登陆状态失效,需要重新登陆 /wlogin ")
logger.warning { "$type(${id})监听任务执行失败, $e" }
logger.warning { "$type(${id})监听任务执行失败, $exception" }
}
} finally {
logger.info { "$type(${id}): ${tasks[id]}监听任务完成一次, 即将进入延时" }
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/xyz/cssxsh/weibo/Load.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ suspend inline fun WeiboClient.text(url: String, crossinline block: HttpRequestB
}

suspend inline fun <reified T> WeiboClient.json(url: String, crossinline block: HttpRequestBuilder.() -> Unit): T {
val text = useHttpClient { client ->
client.config {
followRedirects = false
}.get<String>(url, block)
val text = useHttpClient<String> { client ->
client.config { followRedirects = false }.get(url, block)
}
check(text.startsWith("{")) {
text.substring(0, minOf(ErrorMessageLength, text.length))
}
val temp = WeiboClient.Json.decodeFromString<TempData>(text)
require(temp.ok) {
check(temp.ok) {
if (temp.url.orEmpty().startsWith(LOGIN_PAGE)) {
"登陆状态无效,请登录"
} else {
Expand Down

0 comments on commit c4a3a16

Please sign in to comment.