From f6af75ae74d84097925a3e917ed592fd948458da Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Mon, 11 Nov 2019 10:57:32 -0500 Subject: [PATCH] =?UTF-8?q?Refactor=20the=20Read=20Namespace=20requests=20?= =?UTF-8?q?to=20not=20use=20the=20query=20funct=E2=80=A6=20(#6720)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The query function doesn’t handle non-200 return codes properly so this ended up still trying to decode the body which resulted in weird error messages. --- api/namespace.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/api/namespace.go b/api/namespace.go index cfcc1b815c..9e1fead2e8 100644 --- a/api/namespace.go +++ b/api/namespace.go @@ -100,10 +100,25 @@ func (n *Namespaces) Update(ns *Namespace, q *WriteOptions) (*Namespace, *WriteM func (n *Namespaces) Read(name string, q *QueryOptions) (*Namespace, *QueryMeta, error) { var out Namespace - qm, err := n.c.query("/v1/namespace/"+name, &out, q) + r := n.c.newRequest("GET", "/v1/namespace/"+name) + r.setQueryOptions(q) + found, rtt, resp, err := requireNotFoundOrOK(n.c.doRequest(r)) if err != nil { return nil, nil, err } + defer resp.Body.Close() + + qm := &QueryMeta{} + parseQueryMeta(resp, qm) + qm.RequestTime = rtt + + if !found { + return nil, qm, nil + } + + if err := decodeBody(resp, &out); err != nil { + return nil, nil, err + } return &out, qm, nil } @@ -122,10 +137,20 @@ func (n *Namespaces) Delete(name string, q *WriteOptions) (*WriteMeta, error) { func (n *Namespaces) List(q *QueryOptions) ([]*Namespace, *QueryMeta, error) { var out []*Namespace - qm, err := n.c.query("/v1/namespaces", &out, q) + r := n.c.newRequest("GET", "/v1/namespaces") + r.setQueryOptions(q) + rtt, resp, err := requireOK(n.c.doRequest(r)) if err != nil { return nil, nil, err } + defer resp.Body.Close() + + qm := &QueryMeta{} + parseQueryMeta(resp, qm) + qm.RequestTime = rtt + if err := decodeBody(resp, &out); err != nil { + return nil, nil, err + } return out, qm, nil }