如何在 netsuite 中使用 suitescript 2.0 在没有堆栈跟踪的情况下显示自定义错误消息
How to show the custom error message without stack trace using suitescript 2.0 in netsuite
我想向使用 "suitescript 2.0" 版本的用户显示没有堆栈跟踪的自定义错误消息。在工作流程中,自定义错误消息显示时没有堆栈跟踪,但在 Suite 脚本中 "ERROR MESSAGE " 显示时带有堆栈跟踪。
堆栈跟踪错误:
{"type":"error.SuiteScriptError","name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract.","stack":["createError(N/error)", "beforeSubmit(SuiteScripts/Ex_UE_Contract_2.0.js:117)","createError(N/error)"],"cause":{"name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract."},"id" :""}
我想像这样显示没有堆栈跟踪的自定义错误消息:
"name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract."
我的代码:
throw error.create({
name: 'MISSING_CONTRACT_LINE',
message: 'Please enter atleast one Contract Line item to save a contract.'
});
有什么方法可以实现吗?
提前致谢。
N/error 的 SuiteScriptError#toString() 方法的默认实现是调用 JSON.stringify(this),但是,该方法可以按实例覆盖以处理原始错误消息的情况旨在通过从脚本中抛出错误来向用户显示。例如:
var err = error.create({name: 'NO_JSON', message: 'This should not be displayed as JSON!'})
err.toString = function(){return err.message};
throw err;
或者,也可以只抛出一个字符串,但是,中间的 catch 块将失去访问错误的其他属性的好处,例如 Error#stack 或 Error#name。
套件脚本版本 2.0:
首先在函数的顶部定义 'N/error' 模块。
var errorObj = error.create({
code: 'Custom Error Message Without JSON',
message: 'Custom Error Message Without JSON'
});
throw errorObj.code + '\n\n' + errorObj.message;
return false;
如果您不想显示错误代码,只需使用 errorObj.message 它只会显示消息。
我想向使用 "suitescript 2.0" 版本的用户显示没有堆栈跟踪的自定义错误消息。在工作流程中,自定义错误消息显示时没有堆栈跟踪,但在 Suite 脚本中 "ERROR MESSAGE " 显示时带有堆栈跟踪。
堆栈跟踪错误: {"type":"error.SuiteScriptError","name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract.","stack":["createError(N/error)", "beforeSubmit(SuiteScripts/Ex_UE_Contract_2.0.js:117)","createError(N/error)"],"cause":{"name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract."},"id" :""}
我想像这样显示没有堆栈跟踪的自定义错误消息: "name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract."
我的代码:
throw error.create({
name: 'MISSING_CONTRACT_LINE',
message: 'Please enter atleast one Contract Line item to save a contract.'
});
有什么方法可以实现吗?
提前致谢。
N/error 的 SuiteScriptError#toString() 方法的默认实现是调用 JSON.stringify(this),但是,该方法可以按实例覆盖以处理原始错误消息的情况旨在通过从脚本中抛出错误来向用户显示。例如:
var err = error.create({name: 'NO_JSON', message: 'This should not be displayed as JSON!'})
err.toString = function(){return err.message};
throw err;
或者,也可以只抛出一个字符串,但是,中间的 catch 块将失去访问错误的其他属性的好处,例如 Error#stack 或 Error#name。
套件脚本版本 2.0:
首先在函数的顶部定义 'N/error' 模块。
var errorObj = error.create({
code: 'Custom Error Message Without JSON',
message: 'Custom Error Message Without JSON'
});
throw errorObj.code + '\n\n' + errorObj.message;
return false;
如果您不想显示错误代码,只需使用 errorObj.message 它只会显示消息。