(api, method string, callback base.ReqCallback, retry ...bool)
| 32 | } |
| 33 | |
| 34 | func (d *AListV3) request(api, method string, callback base.ReqCallback, retry ...bool) ([]byte, int, error) { |
| 35 | url := d.Address + "/api" + api |
| 36 | req := base.RestyClient.R() |
| 37 | req.SetHeader("Authorization", d.Token) |
| 38 | if callback != nil { |
| 39 | callback(req) |
| 40 | } |
| 41 | res, err := req.Execute(method, url) |
| 42 | if err != nil { |
| 43 | code := 0 |
| 44 | if res != nil { |
| 45 | code = res.StatusCode() |
| 46 | } |
| 47 | return nil, code, err |
| 48 | } |
| 49 | log.Debugf("[alist_v3] response body: %s", res.String()) |
| 50 | if res.StatusCode() >= 400 { |
| 51 | return nil, res.StatusCode(), fmt.Errorf("request failed, status: %s", res.Status()) |
| 52 | } |
| 53 | code := utils.Json.Get(res.Body(), "code").ToInt() |
| 54 | if code != 200 { |
| 55 | if (code == 401 || code == 403) && !utils.IsBool(retry...) { |
| 56 | err = d.login() |
| 57 | if err != nil { |
| 58 | return nil, code, err |
| 59 | } |
| 60 | return d.request(api, method, callback, true) |
| 61 | } |
| 62 | return nil, code, fmt.Errorf("request failed,code: %d, message: %s", code, utils.Json.Get(res.Body(), "message").ToString()) |
| 63 | } |
| 64 | return res.Body(), 200, nil |
| 65 | } |
no test coverage detected