Skip to content

Commit

Permalink
Log non-OK notification responses
Browse files Browse the repository at this point in the history
  • Loading branch information
hryx committed Oct 18, 2022
1 parent 4c68b7e commit f09da29
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 14 additions & 5 deletions zipserver/extract_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -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))
}
})()

Expand Down
14 changes: 12 additions & 2 deletions zipserver/slurp_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
})()

Expand Down

0 comments on commit f09da29

Please sign in to comment.