MCPcopy
hub / github.com/dgraph-io/dgraph / SetStatusWithData

Function SetStatusWithData

x/x.go:407–420  ·  view source on GitHub ↗

SetStatusWithData sets the errors in the response and ensures that the data key in the data is present with value nil. In case an error was encountered after the query execution started, we have to return data key with null value according to GraphQL spec.

(w http.ResponseWriter, code, msg string)

Source from the content-addressed store, hash-verified

405// In case an error was encountered after the query execution started, we have to return data
406// key with null value according to GraphQL spec.
407func SetStatusWithData(w http.ResponseWriter, code, msg string) {
408 var qr QueryResWithData
409 ext := make(map[string]interface{})
410 ext["code"] = code
411 qr.Errors = append(qr.Errors, &GqlError{Message: msg, Extensions: ext})
412 // This would ensure that data key is present with value null.
413 if js, err := json.Marshal(qr); err == nil {
414 if _, err := w.Write(js); err != nil {
415 glog.Errorf("Error while writing: %+v", err)
416 }
417 } else {
418 Panic(errors.Errorf("Unable to marshal: %+v", qr))
419 }
420}
421
422// Reply sets the body of an HTTP response to the JSON representation of the given reply.
423func Reply(w http.ResponseWriter, rep interface{}) {

Callers 4

loginHandlerFunction · 0.92
queryHandlerFunction · 0.92
mutationHandlerFunction · 0.92
commitHandlerFunction · 0.92

Calls 3

PanicFunction · 0.85
WriteMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected