diff --git a/api/panel/node.go b/api/panel/node.go index d69a533..8a4ea4e 100644 --- a/api/panel/node.go +++ b/api/panel/node.go @@ -68,11 +68,14 @@ type NodeInfo struct { func (c *Client) GetNodeInfo() (node *NodeInfo, err error) { const path = "/api/v1/server/UniProxy/config" - r, err := c.client.R().Get(path) + r, err := c.client. + R(). + SetHeader("If-None-Match", c.etag). + Get(path) if err = c.checkResponse(r, path, err); err != nil { return } - if c.etag == r.Header().Get("ETag") { // node info not changed + if r.StatusCode() == 304 { return nil, nil } // parse common params diff --git a/api/panel/node_test.go b/api/panel/node_test.go index dea16e8..570182f 100644 --- a/api/panel/node_test.go +++ b/api/panel/node_test.go @@ -23,6 +23,7 @@ func init() { func TestClient_GetNodeInfo(t *testing.T) { log.Println(client.GetNodeInfo()) + log.Println(client.GetNodeInfo()) } func TestClient_ReportUserTraffic(t *testing.T) { diff --git a/api/panel/utils.go b/api/panel/utils.go index 938bec9..74ef5b3 100644 --- a/api/panel/utils.go +++ b/api/panel/utils.go @@ -18,7 +18,7 @@ func (c *Client) checkResponse(res *resty.Response, path string, err error) erro if err != nil { return fmt.Errorf("request %s failed: %s", c.assembleURL(path), err) } - if res.StatusCode() != 200 { + if res.StatusCode() >= 400 { body := res.Body() return fmt.Errorf("request %s failed: %s", c.assembleURL(path), string(body)) }