From f09da294f0387fa432d9e4cd6cfdf99284818b3f Mon Sep 17 00:00:00 2001 From: Stevie Hryciw Date: Tue, 18 Oct 2022 16:44:03 -0700 Subject: [PATCH] Log non-OK notification responses --- zipserver/extract_handler.go | 19 ++++++++++++++----- zipserver/slurp_handler.go | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/zipserver/extract_handler.go b/zipserver/extract_handler.go index 67ca8ae..f70c058 100644 --- a/zipserver/extract_handler.go +++ b/zipserver/extract_handler.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "io" "log" "net/http" "net/url" @@ -170,11 +171,19 @@ func extractHandler(w http.ResponseWriter, r *http.Request) error { } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - asyncResponse, err := http.DefaultClient.Do(req) - if err == nil { - asyncResponse.Body.Close() - } else { - log.Print("Failed to deliver callback: " + err.Error()) + res, err := http.DefaultClient.Do(req) + if err != nil { + log.Printf("Failed to deliver callback: %v", err) + return + } + defer res.Body.Close() + if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNoContent { + body, err := io.ReadAll(res.Body) + if err != nil { + log.Printf("Read notification response: %v", err) + return + } + log.Printf("Notification response: %s %s", res.Status, string(body)) } })() diff --git a/zipserver/slurp_handler.go b/zipserver/slurp_handler.go index 3839e20..df85178 100644 --- a/zipserver/slurp_handler.go +++ b/zipserver/slurp_handler.go @@ -145,9 +145,19 @@ func slurpHandler(w http.ResponseWriter, r *http.Request) error { } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = http.DefaultClient.Do(req) + res, err := http.DefaultClient.Do(req) if err != nil { - log.Print("Failed to deliver callback: " + err.Error()) + log.Printf("Failed to deliver callback: %v", err) + return + } + defer res.Body.Close() + if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNoContent { + body, err := io.ReadAll(res.Body) + if err != nil { + log.Printf("Read notification response: %v", err) + return + } + log.Printf("Notification response: %s %s", res.Status, string(body)) } })()