In my application, when there is error I am writing a json error message on response body but this makes response code 200. I tried separately doing
json.NewEncoder(res).Encode(errorBody)
res.WriteHeader(http.StatusBadRequest)
But it still gives out response code 200 along with a warning that I am making multiple WriteHeader calls. I want to have something like
http.Error(res,"Some Error Message here",http.StatusBadRequest)
but instead of the error message in text format, I want it to be in JSON. What should I do?