Ejemplo n.º 1
0
        /// <summary>
        /// Creates Exception Info Response
        /// </summary>
        /// <param name="context"></param>
        /// <param name="errors"></param>
        /// <param name="errorConstant"></param>
        /// <param name="httpStatusCode"></param>
        /// <returns></returns>
        private IActionResult CreateExceptionInfoResponse(ActionContext context, IEnumerable <string> errors, string errorConstant, HttpStatusCode httpStatusCode)
        {
            if (errors == null || errors.Any(x => String.IsNullOrWhiteSpace(x)))
            {
                errors = new List <string> {
                    errorConstant
                };
            }

            var errorInfo = new ErrorInfoResponse()
            {
                Messages = new List <ErrorMessage>()
            };

            foreach (var error in errors)
            {
                var errorMessage = new ErrorMessage()
                {
                    Code    = $"TaxApi.{error}",
                    Message = $"TaxApi.{error}"
                };

                errorInfo.Messages.Add(errorMessage);
            }

            var result = new ObjectResult(errorInfo)
            {
                StatusCode = (int)httpStatusCode
            };

            _logger.LogError($"Error = {result.StatusCode}");

            return(result);
        }
Ejemplo n.º 2
0
        private IActionResult UnAuthorizedExceptionInfoResponse()
        {
            var errorInfo = new ErrorInfoResponse()
            {
                Messages = new List <ErrorMessage>()
            };
            var errorMessage = new ErrorMessage()
            {
                Code    = $"TaxApi.UnAuthorized",
                Message = $"TaxApi.UnAuthorized"
            };

            errorInfo.Messages.Add(errorMessage);


            var result = new ObjectResult(errorInfo)
            {
                StatusCode = (int)HttpStatusCode.Unauthorized
            };

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理错上传请求
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ErrorInfoResponse HandleErrorInfoRequest(ErrorInfoRequest request)
        {
            ErrorInfoResponse response = new ErrorInfoResponse
            {
                Uid        = request.Uid,
                DeviceType = request.DeviceType,
                TrainMode  = request.TrainMode,
                Success    = false
            };

            try
            {
                Error error = new Error();
                error.device_type = (int)request.DeviceType;
                error.error_info  = request.Error;
                error.fk_user_id  = Convert.ToInt32(request.Uid);
                error.train_mode  = (int)request.TrainMode;
                error.error_time  = request.ErrorStartTime;
                errorDao.Insert(error);
                UploadManagementDAO uploadManagementDao = new UploadManagementDAO();
                uploadManagementDao.Insert(new UploadManagement(errorDao.GetErrorLastId(), "bdl_error", 0));
            }
            catch (Exception e)
            {
                logger.Error("错误信息插入失败。");
            }

            logger.Error("当前出现错误时间," + request.ErrorStartTime
                         + ",用户id" + request.Uid
                         + ",设备类型" + (int)request.DeviceType
                         + ",训练模式" + (int)request.TrainMode
                         + ",错误信息" + request.Error
                         );
            response.Success = true;
            return(response);
        }