From d32f229ef60417901f169b028967daf151bf3090 Mon Sep 17 00:00:00 2001 From: Ernest Neller Date: Tue, 26 Dec 2023 21:58:02 +0100 Subject: [PATCH 1/3] Skip status 204 as error if the delete method is used. --- client.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index be3cef5..be72ae3 100644 --- a/client.go +++ b/client.go @@ -100,14 +100,16 @@ func (client *Client) sendRequest(req *http.Request, dest interface{}) error { client.logger.Debug(string(body)) } - if resp.StatusCode != http.StatusOK { - return &unexpectedStatusError{ - status: resp.StatusCode, - url: req.URL, + if req.Method != http.MethodDelete && resp.StatusCode != http.StatusNoContent { + if resp.StatusCode != http.StatusOK { + return &unexpectedStatusError{ + status: resp.StatusCode, + url: req.URL, + } } } - if dest != nil { + if dest != nil && len(body) > 0 { if err := json.NewDecoder(bytes.NewReader(body)).Decode(dest); err != nil { return fmt.Errorf("directus: cannot decode response: %v", err) } From 192157ffbec6ebb3feeed266197530bf02281608 Mon Sep 17 00:00:00 2001 From: Ernest Neller Date: Tue, 26 Dec 2023 22:25:31 +0100 Subject: [PATCH 2/3] Skip status 204 as error if the delete method is used. --- client.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index be72ae3..d9c43b1 100644 --- a/client.go +++ b/client.go @@ -100,12 +100,10 @@ func (client *Client) sendRequest(req *http.Request, dest interface{}) error { client.logger.Debug(string(body)) } - if req.Method != http.MethodDelete && resp.StatusCode != http.StatusNoContent { - if resp.StatusCode != http.StatusOK { - return &unexpectedStatusError{ - status: resp.StatusCode, - url: req.URL, - } + if resp.StatusCode != http.StatusOK && (req.Method != http.MethodDelete && resp.StatusCode != http.StatusNoContent) { + return &unexpectedStatusError{ + status: resp.StatusCode, + url: req.URL, } } From b26f2004960050e4c6bc6a874ae23cbd73383ae3 Mon Sep 17 00:00:00 2001 From: Ernest Neller Date: Tue, 26 Dec 2023 23:07:06 +0100 Subject: [PATCH 3/3] Skip status 204 as error if the delete method is used. --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index d9c43b1..f6afa4e 100644 --- a/client.go +++ b/client.go @@ -100,7 +100,7 @@ func (client *Client) sendRequest(req *http.Request, dest interface{}) error { client.logger.Debug(string(body)) } - if resp.StatusCode != http.StatusOK && (req.Method != http.MethodDelete && resp.StatusCode != http.StatusNoContent) { + if resp.StatusCode != http.StatusOK && req.Method != http.MethodDelete && resp.StatusCode != http.StatusNoContent { return &unexpectedStatusError{ status: resp.StatusCode, url: req.URL,