Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #24 from secrethub/feature/write-response-errs
Browse files Browse the repository at this point in the history
Log errors when writing a response fails
  • Loading branch information
SimonBarendse authored Apr 30, 2019
2 parents bc6d46b + 94a0506 commit de046e1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/restproxy/rest_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -79,7 +80,10 @@ func (p *restProxy) handleSecret(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(http.StatusOK)
w.Write(secret.Data)
_, err = w.Write(secret.Data)
if err != nil {
log.Printf("failed to write HTTP response: %s", err)
}
case "POST":
secret, err := ioutil.ReadAll(r.Body)
if err != nil {
Expand Down Expand Up @@ -130,5 +134,8 @@ func writeError(w http.ResponseWriter, err error, statusCode int) {
}

w.WriteHeader(statusCode)
io.WriteString(w, err.Error())
_, err = io.WriteString(w, err.Error())
if err != nil {
log.Printf("failed to write error to HTTP response: %s", err)
}
}

0 comments on commit de046e1

Please sign in to comment.