Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to show the custom error message with out stack trace to user using "suitescript 2.0"version. In workflow the custom error message is showing without stack trace but in Suite Script the "ERROR MESSAGE " is showing with the stack trace.

ERROR WITH STACK TRACE: {"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":""}

I want to show the custom error message without stack trace like this: "name":"MISSING_CONTRACT_LINE","message":"Please enter atleast one Contract Line item to save a contract."

my Code:

     throw error.create({
         name: 'MISSING_CONTRACT_LINE',
         message: 'Please enter atleast one Contract Line item to save a contract.'
     });

is there any possible way to achieve this?

thanks in advance.

like image 814
Deepan Murugan Avatar asked Mar 12 '23 14:03

Deepan Murugan


1 Answers

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.

like image 160
playalpha Avatar answered Apr 23 '23 15:04

playalpha