public static string ReturnError(string path, string rcode, Exception exception = null) { Lion.ExAPI.Utility.Hangfire.Models.V2.ResponseBase RespBaseReturnV2 = new Lion.ExAPI.Utility.Hangfire.Models.V2.ResponseBase(); rCodeStatusEnumLog rCode = rCodeStatusEnumLog.rCode_0005; if (rcode != "200") { byte[] utf8Bytes = System.Text.Encoding.UTF8.GetBytes(exception.Message); if (path.IndexOf("/v1/") >= 0) { ResponseBase RespBaseReturnV1 = new ResponseBase(); RespBaseReturnV1.IsSuccess = false; RespBaseReturnV1.Data = null; RespBaseReturnV1.Msg = Encoding.UTF8.GetString(utf8Bytes); return(JsonConvert.SerializeObject(RespBaseReturnV1)); } else { RespBaseReturnV2.Data = null; RespBaseReturnV2.rCode = rcode; RespBaseReturnV2.rDesc = Encoding.UTF8.GetString(utf8Bytes); RespBaseReturnV2.TokenExpires = DateTime.MinValue; return(JsonConvert.SerializeObject(RespBaseReturnV2)); } } else { if (path.IndexOf("/v1/") >= 0) { ResponseBase RespBaseReturnV1 = new ResponseBase(); RespBaseReturnV1.IsSuccess = false; RespBaseReturnV1.Data = null; RespBaseReturnV1.Msg = "API System error"; return(JsonConvert.SerializeObject(RespBaseReturnV1)); } else { RespBaseReturnV2.Data = null; RespBaseReturnV2.rCode = rCode.Get_rCode(); RespBaseReturnV2.rDesc = rCode.Get_rCodeDesc(); RespBaseReturnV2.TokenExpires = DateTime.MinValue; return(JsonConvert.SerializeObject(RespBaseReturnV2)); } } }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { rCodeStatusEnumLog rCode0005 = rCodeStatusEnumLog.rCode_0005; try { base.OnActionExecuted(actionExecutedContext); if (actionExecutedContext.Exception != null) { throw new Exception(); } } catch { if (actionExecutedContext.Request.RequestUri.ToString().ToLower().Contains("/v2/")) { Models.V2.ResponseBase <string> rError = new Models.V2.ResponseBase <string>() { Data = string.Empty, rCode = rCode0005.Get_rCode(), rDesc = rCode0005.Get_rCodeDesc() }; actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(actionExecutedContext.Response.StatusCode, rError); } else if (actionExecutedContext.Request.RequestUri.ToString().ToLower().Contains("/v1/")) { ResponseBase <string> rError = new ResponseBase <string>() { Data = null, IsSuccess = false, Msg = "API System error" }; actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(actionExecutedContext.Response.StatusCode, rError); } else { actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(actionExecutedContext.Response.StatusCode, "系統錯誤,請通知api人員謝謝!!"); } } finally { //計算時間 Stopwatch stopwatch = (Stopwatch)actionExecutedContext.Request.Properties[actionExecutedContext.ActionContext.ActionDescriptor.ActionName]; HttpContext.Current.Items[SettingHelper.Action_Timer] = stopwatch.ElapsedMilliseconds; NetHandlingLogContext data = new NetHandlingLogContext(actionExecutedContext, HttpContext.Current); Models.connectModel = data.returnconModel(); Models.errModel = data.returnerrModel(); //postLoghttpWebRequest(Models); postLogWebClient(Models); //postLog(Models).ConfigureAwait(false); //Start(Models); //Task.Run(async () => //{ // await postLog(Models).ConfigureAwait(false); //}).ConfigureAwait(false); //Task.Run(() => //{ // HttpRequestAsync(Models); //}).ConfigureAwait(false); } }