Skip to content

Commit

Permalink
Log callback failed to write response error (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaiaz-iusipov authored Dec 22, 2024
1 parent 9dae20b commit dbf7c2a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions callback/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (cb *Callback) HandleFunc(w http.ResponseWriter, r *http.Request) {
}

if remove {
_, _ = w.Write([]byte("remove"))
cb.response(w, "remove")

return
}
Expand All @@ -122,10 +122,17 @@ func (cb *Callback) HandleFunc(w http.ResponseWriter, r *http.Request) {
return
}

_, _ = w.Write([]byte("ok"))
cb.response(w, "ok")
}

func (cb *Callback) logf(format string, args ...interface{}) {
func (cb *Callback) response(w http.ResponseWriter, data string) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
if _, err := w.Write([]byte(data)); err != nil {
cb.logf("write response: %v", err)
}
}

func (cb *Callback) logf(format string, args ...any) {
if cb.ErrorLog != nil {
cb.ErrorLog.Printf(format, args...)
} else {
Expand Down

0 comments on commit dbf7c2a

Please sign in to comment.