[HttpGet("{subPath}/Md/{fieldId}")] //IEnumerable<AxEnum> public object Get(String subPath, String fieldId, [FromQuery] IntervalParameters parameters) { ICommonError err = errorBuilder.Success(""); object ret; var uri = this.HttpContext.Request.Path.ToUriComponent(); if (uri.Substring(uri.Length - 3) == "/Md") { var md = contextHelper.GetMetadata(context, subPath) as IMetadataBase <object, string>; ret = (md != null) ? mdHelper.GetMetadataByQuery(this.Request.Query, md) : this.BadReqErr("Resource [" + subPath + "] not found"); } else if (fieldId != null) { var md = contextHelper.GetMetadataField(context, subPath, fieldId) as IMetadataBase <object, string>; ret = (md != null) ? mdHelper.GetMetadataByQuery(this.Request.Query, md) : this.BadReqErr("Resource [" + subPath + "] not found"); } else { if (this.Request.Query.Count > 0) { object[] par = { contextHelper.ToKeyValuePairFromRequest(this.Request) }; var resp = contextHelper.InvokeReaderMethod(context, subPath, "Get", par); ret = resp ?? this.BadReqErr("Resource [" + subPath + "] not found"); } else { var resp = contextHelper.InvokeReaderMethod(context, subPath, "GetAll"); ret = resp ?? this.BadReqErr("Resource [" + subPath + "] not found"); } } return(ret); }
// Build Error private ICommonError BadReqErr(string msg) { ICommonError err = errorBuilder.ClientError("Bad Request: " + msg); err.StatusCode = 400; //err.Message = msg; errorBuilder.EerectTo(err, this.Response); return(err); }
protected static string ToJson(ICommonError err) { StringBuilder sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine("\"name\":\"" + err.Name + "\","); sb.AppendLine("\"message\":\"" + err.Message + "\","); sb.AppendLine("\"code\":" + err.Code.ToString() + ","); sb.AppendLine("\"statusCode\":" + err.StatusCode.ToString() + ""); sb.AppendLine("}"); return(sb.ToString()); }
public object Post([FromBody] NVASD_Incoming value) { ICommonError err = _errorBuilder.Success(""); object ret; if (value != null) { _context.NvaSdIncoming.Access.Inserter.Add(value); var rt = _context.Save(); if (rt != null && rt != "") { err = _errorBuilder.ClientError(rt); err.Name = "Unprocessable Entity"; err.StatusCode = 422; _errorBuilder.EerectTo(err, this.Response); ret = err; } else { ret = _context.NvaSdIncoming.Access.Reader.Find(value.ID); } } else { //this.Response.Body.Position = 0; var s = ""; if (this.Request.Body.Length > 0) { this.Request.Body.Position = 0; s = new StreamReader(this.Request.Body, Encoding.UTF8).ReadToEnd(); } err = _errorBuilder.ClientError("Bad Request"); err.StatusCode = 400; err.Message = string.IsNullOrEmpty(s) ? "Incoming data is empty" : "Incoming data is bad: [" + s + "]"; _errorBuilder.EerectTo(err, this.Response); ret = err; } return(ret); }
/// <summary> /// /// </summary> /// <param name="commonError"></param> /// <param name="errMsg"></param> public BusinessException(ICommonError commonError, string errMsg) : base() { this.commonError = commonError; this.commonError.SetErrMsg(errMsg); }
/// <summary> /// 直接接收EmBusinessError的传参用于构造业务异常 /// </summary> /// <param name="commonError"></param> public BusinessException(ICommonError commonError) : base() { this.commonError = commonError; }
public static Resp <T> End(ICommonError value) => new Resp <T>(value);
private Resp(ICommonError responce) { resp = responce; }
public string ToJsonString(ICommonError err) => ToJson(err);
public void EerectTo(ICommonError error, TTarget targetObj) { ErectFunc(error, targetObj); }