private void Log(IInvocation invocation, Exception exception, LogType logType) { var requestDTOBase = GetRequestDtoBase(invocation); BaseResponseDTO baseResponseDto = invocation.ReturnValue as BaseResponseDTO; logger.Log(requestDTOBase.TrackId, $" ResponseCode:{baseResponseDto.Header.ResponseCode}, Method: {invocation.Method.Name}, Message: {exception}", "", logType); }
public BaseResponseDTO AnalyzeRisk([FromBody] RiskAnalysisParameterDTO parameter) { BaseResponseDTO result = new BaseResponseDTO(); try { result = _riskAnalysisService.AnalyzeRisk(parameter); } catch (Exception exception) { _logger.LogError(exception, ""); } return(result); }
private static Task HandleExceptionAsync(HttpContext context, Exception ex) { var code = HttpStatusCode.InternalServerError; // 500 if unexpected var result = new BaseResponseDTO <string>() { ErrorCode = (int)HttpStatusCode.InternalServerError, ErrorMessage = ex.Message, Succeed = false, }; var jsonResult = JsonConvert.SerializeObject(result); context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)code; return(context.Response.WriteAsync(jsonResult)); }
public IActionResult SaveEmployee([FromBody] EmployeeEntity employeeEntity) { BaseResponseDTO baseResponseDTO = new BaseResponseDTO(); try { EmployeeService.SaveEmployee(employeeEntity); baseResponseDTO.IsSuccess = true; } catch (Exception ex) { baseResponseDTO.IsSuccess = false; baseResponseDTO.Message = ex.Message; } return(Ok(baseResponseDTO)); }
public IActionResult SaveProduct([FromBody] ProductEntity productEntity) { BaseResponseDTO baseResponseDTO = new BaseResponseDTO(); try { ProductService.SaveProduct(productEntity); baseResponseDTO.IsSuccess = true; } catch (Exception ex) { baseResponseDTO.IsSuccess = false; baseResponseDTO.Message = ex.Message; } return(Ok(baseResponseDTO)); }
public IActionResult GetAllEmployees() { BaseResponseDTO baseResponseDTO = new BaseResponseDTO(); List <EmployeeEntity> empolyeeList; try { empolyeeList = EmployeeService.GetAllEmployees(); baseResponseDTO.IsSuccess = true; baseResponseDTO.Response = JsonConvert.SerializeObject(empolyeeList); } catch (Exception ex) { baseResponseDTO.IsSuccess = false; baseResponseDTO.Message = ex.Message; } return(Ok(baseResponseDTO)); }
private object GetReturnDto(IInvocation invocation, string errorCode, string responseMessage) { if (invocation.Method.ReturnType == typeof(void)) { return(null); } var returnValue = Activator.CreateInstance(invocation.Method.ReturnType); BaseResponseDTO dto = returnValue as BaseResponseDTO; if (dto != null) { dto.Header.ResponseCode = errorCode; dto.Header.Message = ResponseMessages.Get(errorCode, this.GetLanguageCode(invocation)); } return(returnValue); }
public IActionResult GetAllProducts() { BaseResponseDTO baseResponseDTO = new BaseResponseDTO(); List <ProductEntity> productList; try { productList = ProductService.GetAllProducts(); baseResponseDTO.IsSuccess = true; baseResponseDTO.Response = JsonConvert.SerializeObject(productList); } catch (Exception ex) { baseResponseDTO.IsSuccess = false; baseResponseDTO.Message = ex.Message; } return(Ok(baseResponseDTO)); }
public static F DoGetWithAutoDeserilize <T, F>(string url, T obj) where T : BaseRequestDTO { var response = DoGet <T>(url, obj); if (response == null) { Trace.TraceError("DoGetWithAutoDeserilize方法=====>网络请求异常,请检查网络,请求url={0},请求参数={1}", url, obj.ToString()); throw new Exception("网络请求异常,请检查网络!"); } BaseResponseDTO <F> result = null; try { result = JsonConvert.DeserializeObject <BaseResponseDTO <F> >(response); } catch (Exception exp) { Trace.TraceError("DoGetWithAutoDeserilize方法=====>JsonConvert.DeserializeObject函数异常!,检测参数是否正确,异常信息e={0},请求url={1},请求参数={2}", exp.Message, url, obj.ToString()); throw new Exception("JsonConvert.DeserializeObject函数异常!"); } if (result == null) { Trace.TraceError("DoGetWithAutoDeserilize方法=====>解析json异常,检测参数是否正确,请求url={0},请求参数={1}", url, obj.ToString()); throw new Exception("解析json异常,检测参数是否正确!"); } if (result.Status != (int)Common.http.response.StatusCodeEnum.OK) { Trace.TraceError("DoGetWithAutoDeserilize方法=====>解析json异常,检测ak或sn是否正确,请求url={0},请求参数={1}", url, obj.ToString()); throw new Exception("网络请求状态异常,检测ak或sn是否正确!"); } if (result.Results == null) { Trace.TraceError("DoGetWithAutoDeserilize方法=====>解析json异常,json为空,请求url={0},请求参数={1}", url, obj.ToString()); throw new Exception("解析json异常,json为空!"); } return(result.Results); }
public BaseResponse() { StateResponse = new BaseResponseDTO(); }