コード例 #1
0
        private async Task HandleException(HttpContext httpContext, Exception ex)
        {
            httpContext.Response.StatusCode  = 500;
            httpContext.Response.ContentType = "text/json;charset=utf-8";
            string error = string.Empty;

#if DEBUG
            var json = new { message = ex.Message, trace = ex.StackTrace };
            error = JsonConvert.SerializeObject(json);
#elif RELEASE
            error = "出错了";
            var json = new { message = ex.Message, trace = ex.StackTrace };
#endif

            NLogHelper.GetLogger().Info(error);
            //rabbitmq就绪 json
            var post = new SendEmailOptions
            {
                title   = "位置异常",
                content = JsonConvert.SerializeObject(json)
            };
            if (ex.Message == "NotAllowed")
            {
                await httpContext.Response.WriteAsync(ex.Message);
            }
            else
            {
                this.SendErrorEmail(post);
                await httpContext.Response.WriteAsync(error);
            }
        }
コード例 #2
0
 protected void SendErrorEmail(SendEmailOptions sendEmailOptions)
 {
     try
     {
         sendEmailOptions.sendTo = string.IsNullOrEmpty(sendEmailOptions.sendTo) ?
                                   _appSettings.Value.MainEmail.UserAddress : sendEmailOptions.sendTo;
         var succ = GK2823.BizLib.Shared.RabbitMQHelper.Send(
             _appSettings.Value.MQHandle.DefaultQueue.QueueName,
             System.Text.Json.JsonSerializer.Serialize(sendEmailOptions),
             _appSettings.Value.MQHandle.DefaultQueue.MQFunction.SendEmail);
         if (!succ)
         {
             throw (new Exception("自定义消息队列异常-From Web"));
         }
     }
     catch (Exception ex)
     {
         NLogHelper.GetLogger().Info("消息队列异常-From Web:" + ex.Message + ex.StackTrace);
         AutofacContainer.Resolve <Service_xuangubao>().SendEmail(sendEmailOptions.sendTo, sendEmailOptions.title, sendEmailOptions.content);
     }
 }
コード例 #3
0
        private async Task HandleException(HttpContext httpContext, Exception ex)
        {
            httpContext.Response.StatusCode  = 500;
            httpContext.Response.ContentType = "text/json;charset=utf-8";
            string error = string.Empty;

#if DEBUG
            var json = new { message = ex.Message, trace = ex.StackTrace };
            error = JsonConvert.SerializeObject(json);
#elif RELEASE
            error = "出错了";
            var json = new { message = ex.Message, trace = ex.StackTrace };
#endif
            NLogHelper.GetLogger().Info(error);
            //rabbitmq就绪 json
            var post = new SendEmailOptions
            {
                title   = "位置异常",
                content = JsonConvert.SerializeObject(json)
            };
            if (ex.Message == "NotAllowed")
            {
                await httpContext.Response.WriteAsync(ex.Message);
            }
            else if (ex.Message == ((int)System.Net.HttpStatusCode.Unauthorized).ToString())
            {
                var msg = new MsgResult();
                msg.code = (int)System.Net.HttpStatusCode.Unauthorized;
                msg.data = "请登录";
                httpContext.Response.StatusCode = 401;
                await httpContext.Response.WriteAsync(JsonConvert.SerializeObject(msg));
            }
            else
            {
#if RELEASE
                this.SendErrorEmail(post);
#endif
                await httpContext.Response.WriteAsync(error);
            }
        }