1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(api): replace all calls to http.Error with custom Error writer

This commit is contained in:
Anthony Lapenna 2017-01-24 16:35:48 +13:00
parent 1a868be6ea
commit d03e992b4f
4 changed files with 10 additions and 11 deletions

View file

@ -1,7 +1,6 @@
package http
import (
"fmt"
"io/ioutil"
"log"
"net/http"
@ -40,15 +39,13 @@ func (handler *TemplatesHandler) handleGetTemplates(w http.ResponseWriter, r *ht
resp, err := http.Get(handler.templatesURL)
if err != nil {
log.Print(err)
http.Error(w, fmt.Sprintf("Error making request to %s: %s", handler.templatesURL, err.Error()), http.StatusInternalServerError)
Error(w, err, http.StatusInternalServerError, handler.Logger)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Print(err)
http.Error(w, "Error reading body from templates URL", http.StatusInternalServerError)
Error(w, err, http.StatusInternalServerError, handler.Logger)
return
}
w.Header().Set("Content-Type", "application/json")