PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, November 14, 2022

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

 November 14, 2022     error-handling, javascript, netsuite, suitescript     No comments   

Issue

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.


Solution

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.



Answered By - playalpha
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing