More errors

This commit is contained in:
Tyler 2018-08-02 20:03:32 -04:00
parent 3d264bbfd1
commit 7fb692c15c
1 changed files with 12 additions and 7 deletions

19
main.go
View File

@ -83,12 +83,19 @@ type tableRow struct {
ItemCount int `json:"itemCount"`
}
type response struct {
Success bool `json:"success"`
Message string `json:"message"`
}
func getRecords(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
zone := p.ByName("zone")
hosts := make(map[string]string)
if err := c.Hgetall(key, hosts); err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(&response{Success: false, Message: "Unable to retrieve records: " + err.Error()})
return
}
@ -158,11 +165,6 @@ type domainRequest struct {
Group bool `json:"group"`
}
type response struct {
Success bool `json:"success"`
Message string `json:"message"`
}
func updateRecord(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var req domainRequest
@ -181,6 +183,7 @@ func updateRecord(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
}
if _, err := c.Hset(key, req.Domain, []byte(req.IP)); err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(&response{Success: false, Message: "Unable to save record: " + err.Error()})
return
}
@ -208,7 +211,8 @@ func removeRecord(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
hosts := make(map[string]string)
if err := c.Hgetall(key, hosts); err != nil {
json.NewEncoder(w).Encode(&response{Success: false, Message: "Unable to fetch records"})
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(&response{Success: false, Message: "Unable to fetch records: " + err.Error()})
return
}
@ -225,7 +229,8 @@ func removeRecord(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
}
} else {
if _, err := c.Hdel(key, req.Domain); err != nil {
json.NewEncoder(w).Encode(&response{Success: false, Message: "Unable to delete record"})
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(&response{Success: false, Message: "Unable to delete record: " + err.Error()})
return
}