SetStatus sets the error code, message and the newly assigned uids in the http response.
(w http.ResponseWriter, code, msg string)
| 348 | // SetStatus sets the error code, message and the newly assigned uids |
| 349 | // in the http response. |
| 350 | func SetStatus(w http.ResponseWriter, code, msg string) { |
| 351 | w.Header().Set("Content-Type", "application/json") |
| 352 | var qr queryRes |
| 353 | ext := make(map[string]interface{}) |
| 354 | ext["code"] = code |
| 355 | qr.Errors = append(qr.Errors, &GqlError{Message: msg, Extensions: ext}) |
| 356 | if js, err := json.Marshal(qr); err == nil { |
| 357 | if _, err := w.Write(js); err != nil { |
| 358 | glog.Errorf("Could not send error msg=%+v code=%+v due to http error %+v", msg, code, err) |
| 359 | } |
| 360 | } else { |
| 361 | Panic(errors.Errorf("Unable to marshal: %+v", qr)) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func SetStatusWithErrors(w http.ResponseWriter, code string, errs []string) { |
| 366 | var qr queryRes |
no test coverage detected