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
178 | 178 |
|
179 | 179 |
// encode errors from business-logic
|
180 | 180 |
func encodeError(_ context.Context, err error, w http.ResponseWriter) {
|
|
181 |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
181 | 182 |
switch err {
|
182 | 183 |
case cargo.ErrUnknown:
|
183 | 184 |
w.WriteHeader(http.StatusNotFound)
|
|
186 | 187 |
default:
|
187 | 188 |
w.WriteHeader(http.StatusInternalServerError)
|
188 | 189 |
}
|
189 | |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
190 | 190 |
json.NewEncoder(w).Encode(map[string]interface{}{
|
191 | 191 |
"error": err.Error(),
|
192 | 192 |
})
|
84 | 84 |
|
85 | 85 |
// encode errors from business-logic
|
86 | 86 |
func encodeError(_ context.Context, err error, w http.ResponseWriter) {
|
|
87 |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
87 | 88 |
switch err {
|
88 | 89 |
case cargo.ErrUnknown:
|
89 | 90 |
w.WriteHeader(http.StatusNotFound)
|
|
92 | 93 |
default:
|
93 | 94 |
w.WriteHeader(http.StatusInternalServerError)
|
94 | 95 |
}
|
95 | |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
96 | 96 |
json.NewEncoder(w).Encode(map[string]interface{}{
|
97 | 97 |
"error": err.Error(),
|
98 | 98 |
})
|
58 | 58 |
|
59 | 59 |
// encode errors from business-logic
|
60 | 60 |
func encodeError(_ context.Context, err error, w http.ResponseWriter) {
|
|
61 |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
61 | 62 |
switch err {
|
62 | 63 |
case cargo.ErrUnknown:
|
63 | 64 |
w.WriteHeader(http.StatusNotFound)
|
|
66 | 67 |
default:
|
67 | 68 |
w.WriteHeader(http.StatusInternalServerError)
|
68 | 69 |
}
|
69 | |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
70 | 70 |
json.NewEncoder(w).Encode(map[string]interface{}{
|
71 | 71 |
"error": err.Error(),
|
72 | 72 |
})
|