correct header and format for json decoding of error (#411)

This commit is contained in:
Brett Demetris
2018-05-09 09:53:56 -07:00
committed by Jesse Peterson
parent a56ff7d295
commit 8118bf6333

View File

@@ -903,7 +903,9 @@ func apiAuthMiddleware(token string, next http.Handler) http.HandlerFunc {
_, password, ok := r.BasicAuth()
if !ok || password != token {
w.Header().Set("WWW-Authenticate", `Basic realm="micromdm"`)
http.Error(w, `{"error": "you need to log in"}`, http.StatusUnauthorized)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"error": "you need to log in"}`))
return
}
next.ServeHTTP(w, r)