in gdbclient/internal/graphsonv3/reader.go [102:156]
func ReadResponse(msg []byte) (*Response, error) {
if msg == nil {
internal.Logger.Warn("response", zap.String("message", ""))
return nil, nil
}
var respJson responseJson
if err := jsonUnmarshal(msg, &respJson); err != nil {
internal.Logger.Error("response", zap.String("message", string(msg)), zap.Error(err))
return nil, internal.NewDeserializerError("response", msg, err)
}
status := respJson.Status
result := respJson.Result
response := &Response{Code: int(status.Code), RequestID: respJson.RequestId}
if response.Code == RESPONSE_STATUS_AUTHENTICATE {
return response, nil
}
if response.Code == RESPONSE_STATUS_SUCCESS || response.Code == RESPONSE_STATUS_PARITAL_CONTENT {
response.Data = result["data"]
// TODO: result["meta"]
} else if response.Code == RESPONSE_STATUS_NO_CONTENT {
response.Data = nil
} else {
// this is a "success" but represents no results otherwise it is an error
message := status.Message
ret, err := resultRouter(status.Attributes)
if err != nil {
internal.Logger.Error("response attributes", zap.Int("code", response.Code), zap.Error(err), zap.String("raw", string(status.Attributes)))
response.Data = err
} else {
attributes := ret.(map[interface{}]interface{})
stackTrace, ok := attributes[graph.STATUS_ATTRIBUTE_STACK_TRACE].(string)
if !ok {
internal.Logger.Error("response attributes stack trace", zap.Int("code", response.Code), zap.String("raw", string(status.Attributes)))
}
var execptions_str []string
if exceptions, ok := attributes[graph.STATUS_ATTRIBUTE_EXCEPTIONS].([]interface{}); ok {
execptions_str = make([]string, len(exceptions), len(exceptions))
for i := 0; i < len(exceptions); i++ {
if execptions_str[i], ok = exceptions[i].(string); !ok {
internal.Logger.Error("response attributes stack trace", zap.Int("code", response.Code), zap.Int("idx", i), zap.String("raw", string(status.Attributes)))
}
}
}
// set errors to Data
response.Data = internal.NewResponseError(response.Code, message, stackTrace, execptions_str)
}
}
return response, nil
}