From 0493ecd9ef8bfcfb7ee3020169bfc9a205f29607 Mon Sep 17 00:00:00 2001 From: jiuxia211 <2064166368@qq.com> Date: Sat, 7 Dec 2024 21:32:28 +0800 Subject: [PATCH] fix: errno type error --- jwch.go | 8 ++++---- user.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jwch.go b/jwch.go index 2eab5bd..6c539ce 100644 --- a/jwch.go +++ b/jwch.go @@ -79,12 +79,12 @@ func (s *Student) NewRequest() *resty.Request { func (s *Student) GetWithIdentifier(url string) (*html.Node, error) { resp, err := s.NewRequest().SetHeader("Referer", constants.JwchReferer).SetQueryParam("id", s.Identifier).Get(url) if err != nil { - return nil, errno.SSOLoginFailedError.WithErr(err) + return nil, errno.CookieError.WithErr(err) } // 会话过期 TODO: 判断条件有点简陋 if strings.Contains(string(resp.Body()), "重新登录") { - return nil, errno.SSOLoginFailedError + return nil, errno.CookieError } return htmlquery.Parse(bytes.NewReader(resp.Body())) @@ -97,12 +97,12 @@ func (s *Student) PostWithIdentifier(url string, formData map[string]string) (*h s.NewRequest().EnableTrace() if err != nil { - return nil, errno.SSOLoginFailedError.WithErr(err) + return nil, errno.CookieError.WithErr(err) } // Identifier缺失 TODO: 判断条件有点简陋 if strings.Contains(string(resp.Body()), "处理URL失败") { - return nil, errno.SSOLoginFailedError + return nil, errno.CookieError } return htmlquery.Parse(strings.NewReader(strings.TrimSpace(string(resp.Body())))) diff --git a/user.go b/user.go index 1fb8091..05038ed 100644 --- a/user.go +++ b/user.go @@ -127,13 +127,13 @@ func (s *Student) Login() error { // 这里是err == nil 因为禁止了重定向,正常登录是会出现异常的 if err == nil { - return errno.SSOLoginFailedError + return errno.CookieError } data := regexp.MustCompile(`id=(.*?)&`).FindStringSubmatch(err.Error()) if len(data) < 1 { - return errno.SSOLoginFailedError + return errno.CookieError } s.SetIdentifier(data[1]) @@ -167,7 +167,7 @@ func (s *Student) CheckSession() error { res := htmlquery.FindOne(resp, `//*[@id="ContentPlaceHolder1_LB_xh"]`) if res == nil { - return errno.SSOLoginFailedError.WithErr(err) + return errno.CookieError.WithErr(err) } if htmlquery.OutputHTML(res, false) != s.ID {