From 5a10edcd157f6a1d16dea18f137ae6f5a87d5001 Mon Sep 17 00:00:00 2001 From: Doug Black Date: Sun, 26 Jan 2014 13:42:50 -0800 Subject: fixes from issues --- core.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'core.go') diff --git a/core.go b/core.go index c8d7ca9..7f7d0b1 100644 --- a/core.go +++ b/core.go @@ -25,6 +25,7 @@ type Api struct{} func (api *Api) Abort(rw http.ResponseWriter, statusCode int) { rw.WriteHeader(statusCode) + rw.Write([]byte(http.StatusText(statusCode))) } func (api *Api) requestHandler(resource Resource) http.HandlerFunc { @@ -54,12 +55,12 @@ func (api *Api) requestHandler(resource Resource) http.HandlerFunc { return } - responseWriter := json.NewEncoder(rw) + content, err := json.Marshal(data) + if err != nil { + api.Abort(rw, 500) + } rw.WriteHeader(code) - if responseWriter.Encode(data) != nil { - api.Abort(rw, 500) - return - } + rw.Write(content) } } -- cgit