62,041
社区成员
发帖
与我相关
我的任务
分享
......
//扣减充值记录
var payList = GetRemainAmount(context, wxUser.MemberId);
payList = payList.OrderBy(c => c.PayId).ToList();
var sum = payList.Sum(c => c.Amount - c.UsedAmount);
if (info.Price > sum) throw new ShowErrorException("充值余额不足以支付!");
public class MvcHandleErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
base.OnException(context);
context.ExceptionHandled = true;
ResultType resultType = ResultType.error;
string showMessage = string.Empty;
string errorMessage = string.Empty;
//设置异常类型(影响客户端提示的图标)
if (context.Exception is ShowInfoException)
{
resultType = ResultType.info;
}
else if (context.Exception is ShowWarningException)
{
resultType = ResultType.warning;
}
//异常消息处理
if (context.Exception is ShowException)
{
//代码执行会进入这里:显示类异常:在客户端提示
showMessage = context.Exception.Message;
}
else
{
//其他类Exception:优化并记录日志,和本问题无关,代码不进入此处
......
}
context.HttpContext.Response.StatusCode = 200; //发现问题后期补救的措施,想将500错误改为200,无效果
context.Result = new ContentResult { Content = new AjaxResult { state = resultType.ToString(), message = showMessage }.ToJson() };
}
}
$.confirm({
title: '',
text: '是否确定支付'+price+"个xx币以查看联系方式?",
onOK: function () {
$.ajaxEx({
url: "/Info/Item/PayAndView",
type: "post",
param: { id: infoId },
success: function (data) {
self.infoForm.Person(data.Person);
self.infoForm.Phone(data.Phone);
self.infoForm.AmountTag(data.AmountTag);
self.enablePayBtn(false);
}
});
}
});
$.ajaxEx = function (options) {
var defaults = {
url: "",
param: [],
type: "get",
async: false,
beforeSend: null,
complete: null
};
var options = $.extend(defaults, options);
if (options.url == "") return;
if (options.type == "post") {
if ($('[name=__RequestVerificationToken]').length > 0) {
options.param["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
}
}
$.ajax({
url: options.url,
data: options.param,
type: options.type,
dataType: "json",
async: options.async,
success: function (data) {
if (!data.state) { //返回的是Json格式结果集,一般是get操作
if (options.success) options.success(data);
} else { //返回AjaxResult格式的json状态数据,一般是post操作
if (data.state == "success") {
if (options.success) options.success(data);
} else {
$.alert(data.message, "错误");
}
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$.alert(errorThrown, "错误");
},
beforeSend: function () {
if (options.beforeSend) options.beforeSend();
},
complete: function () {
if (options.complete) options.complete();
}
});
}
#if DEBUG
Execute();
#else
try
{
Execute();
}
Catch(Exception ex)
{
记录日志("这个功能.log", DateTime.Now, ex.ToString());
throw;
}
#endif
在 Debug 版本,不 try...cath。在 Release版本中,记录日志(里边有详细的堆栈信息、行号),然后再继续抛出异常。context.HttpContext.Response.StatusCode = 200; //发现问题后期补救的措施,想将500错误改为200,无效果