javascript - 为什么我在客户端上看不到错误异常?
问题描述
我有这个动作方法:
public ActionResult SavePoint(PointRequest point)
{
//some logic
throw new System.ArgumentException("Error, no point found");
}
and this ajax:
function saveFeature(feature, callback, error) {
$.ajax({
url: window.homeUrl + "Feature/SavePoint",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: feature,
success: callback,
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
}
在保存功能功能中,我想提醒异常文本:“错误,找不到点”。
但是 throwedError 是空的,知道为什么在 throwedError 中我看不到错误消息吗?
解决方案
Jaromanda X 和 Brett Caswell 在他们的评论中回答了“为什么”。但你可以这样做:
public ActionResult SavePoint(PointRequest point)
{
try
{
//some logic
}
catch (Exception ex)
{
return BadRequest("Error, no point found");
}
}
或者,将实际错误包含给用户:
public ActionResult SavePoint(PointRequest point)
{
try
{
//some logic
}
catch (Exception ex)
{
return BadRequest($"Error, no point found. Message: {ex.InnerException.Message}");
}
}
推荐阅读
- tensorflow - 在 TensorFlow 图中更改一种节点类型
- javascript - CSS 没有在 webpack 项目中立即加载
- java - 如何将 2 条记录(多对一)的 Result 对象映射到 jOOQ 中它们各自的记录对象中?
- f# - 如何转换任务序列
到 MyType 的序列 - c# - 如何在 MVC 应用程序和控制台应用程序之间共享信息
- c++ - 是否有必要在没有子类构造函数的参数的情况下调用父构造函数?
- c# - 对列表中的重复数据进行分组和删除c#
- android - 如何从 Activity 更新片段 TextView?
- reactjs - 构建成功,没有错误但白屏
- azure - 有没有办法从 Azure 搜索中的词法分析中取回令牌?