Fix HTTP error handling

This commit is contained in:
Star Brilliant
2017-10-04 14:59:50 +08:00
parent 7cdec1d3e1
commit 43337472b4
2 changed files with 13 additions and 11 deletions
+4 -2
View File
@@ -21,6 +21,7 @@ package jsonDNS
import (
"encoding/json"
"log"
"net/http"
"github.com/miekg/dns"
)
@@ -29,7 +30,7 @@ type dnsError struct {
Comment string `json:"Comment,omitempty"`
}
func FormatError(comment string) string {
func FormatError(w http.ResponseWriter, comment string, errcode int) {
errJson := dnsError {
Status: dns.RcodeServerFailure,
Comment: comment,
@@ -38,5 +39,6 @@ func FormatError(comment string) string {
if err != nil {
log.Fatalln(err)
}
return string(errStr)
w.WriteHeader(errcode)
w.Write(errStr)
}