fix: cancel parse requests when modal is closed
点击取消解析时,清空 PQueue 队列并中断正在进行的请求。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -80,11 +81,24 @@ func (client *BiliClient) GetPlayInfo(bvid string, cid int) (*PlayInfo, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body := BaseResV2{}
|
||||
err = json.NewDecoder(response.Body).Decode(&body)
|
||||
defer response.Body.Close()
|
||||
|
||||
// 读取响应体用于调试
|
||||
bodyBytes, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := BaseResV2{}
|
||||
err = json.Unmarshal(bodyBytes, &body)
|
||||
if err != nil {
|
||||
// 返回更详细的错误信息
|
||||
preview := string(bodyBytes)
|
||||
if len(preview) > 200 {
|
||||
preview = preview[:200] + "..."
|
||||
}
|
||||
return nil, fmt.Errorf("JSON解析失败,响应内容: %s", preview)
|
||||
}
|
||||
if body.Code != 0 {
|
||||
return nil, errors.New(body.Message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user