From c349860878ef9fb359d0d7b72f0d1cebf342c604 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 1 Jun 2014 23:14:05 -0500 Subject: [PATCH] Middleware now returns JSON error message --- middleware/middleware.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/middleware/middleware.go b/middleware/middleware.go index 797bc3bf..d07e7672 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -1,6 +1,8 @@ package middleware import ( + "encoding/json" + "fmt" "net/http" ctx "github.com/gorilla/context" @@ -78,5 +80,8 @@ func RequireLogin(handler http.Handler) http.HandlerFunc { } func JSONError(w http.ResponseWriter, c int, m string) { - http.Error(w, m, c) + w.WriteHeader(c) + w.Header().Set("Content-Type", "application/json") + cj, _ := json.MarshalIndent(models.Response{Success: false, Message: m}, "", " ") + fmt.Fprintf(w, "%s", cj) }