fix(updater): 调整 HTTP 响应状态码的校验逻辑顺序
- 修复在 resp 为 nil 时可能引发状态码检查异常的问题 - 将状态码校验移至 defer resp.Body.Close() 之后以确保资源正确释放
This commit is contained in:
1 parent
7632652b7b
commit
b812ff62f8
1 file changed
+5
-1
@@ -102,11 +102,15 @@ func CheckUpdate(force bool) *UpdateInfo {
|
|||||||
|
|
||||||
client := &http.Client{Timeout: httpTimeout}
|
client := &http.Client{Timeout: httpTimeout}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil || resp == nil || resp.StatusCode != http.StatusOK {
|
if err != nil || resp == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var release struct {
|
var release struct {
|
||||||
TagName string `json:"tag_name"`
|
TagName string `json:"tag_name"`
|
||||||
HTMLURL string `json:"html_url"`
|
HTMLURL string `json:"html_url"`
|
||||||
|
|||||||
Reference in new issue
Block a user