How to show the custom error message without stack trace using suitescript 2.0 in netsuite

╄→尐↘猪︶ㄣ 提交于 2019-12-05 17:48:56

The default implementation of N/error's SuiteScriptError#toString() method is to call JSON.stringify(this), however, the method could overridden per instance to handle cases where the raw error message is intended to be displayed to users via throwing the error out of the script. For example:

var err = error.create({name: 'NO_JSON', message: 'This should not be displayed as JSON!'})
err.toString = function(){return err.message};
throw err;

Alternatively, it is possible just to throw a String, however, intervening catch blocks would lose the benefit of accessing other properties of the Error, for example, Error#stack or Error#name.

Suite Script Version 2.0:

First define the 'N/error' Module at the top of your function.

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;

If you doesn't want the Error CODE to be displayed just use the errorObj.message it will display only the Message.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!