Codebase list golang-github-go-kit-kit / f13c712
Merge pull request #538 from bcho/fix-example/set-header fix(example/shipping): header should set before `WriteHeader` Peter Bourgon authored 6 years ago GitHub committed 6 years ago
3 changed file(s) with 3 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
178178
179179 // encode errors from business-logic
180180 func encodeError(_ context.Context, err error, w http.ResponseWriter) {
181 w.Header().Set("Content-Type", "application/json; charset=utf-8")
181182 switch err {
182183 case cargo.ErrUnknown:
183184 w.WriteHeader(http.StatusNotFound)
186187 default:
187188 w.WriteHeader(http.StatusInternalServerError)
188189 }
189 w.Header().Set("Content-Type", "application/json; charset=utf-8")
190190 json.NewEncoder(w).Encode(map[string]interface{}{
191191 "error": err.Error(),
192192 })
8484
8585 // encode errors from business-logic
8686 func encodeError(_ context.Context, err error, w http.ResponseWriter) {
87 w.Header().Set("Content-Type", "application/json; charset=utf-8")
8788 switch err {
8889 case cargo.ErrUnknown:
8990 w.WriteHeader(http.StatusNotFound)
9293 default:
9394 w.WriteHeader(http.StatusInternalServerError)
9495 }
95 w.Header().Set("Content-Type", "application/json; charset=utf-8")
9696 json.NewEncoder(w).Encode(map[string]interface{}{
9797 "error": err.Error(),
9898 })
5858
5959 // encode errors from business-logic
6060 func encodeError(_ context.Context, err error, w http.ResponseWriter) {
61 w.Header().Set("Content-Type", "application/json; charset=utf-8")
6162 switch err {
6263 case cargo.ErrUnknown:
6364 w.WriteHeader(http.StatusNotFound)
6667 default:
6768 w.WriteHeader(http.StatusInternalServerError)
6869 }
69 w.Header().Set("Content-Type", "application/json; charset=utf-8")
7070 json.NewEncoder(w).Encode(map[string]interface{}{
7171 "error": err.Error(),
7272 })