What is the API of new sn_ws_err.NotFoundError

rdelpeso1
Mega Contributor

Hi,

 

Has anyone figured out the API for new sn_ws_err.NotFoundError to grab the message/status that it holds inside?

 

example:

 

var err = new sn_ws_err.NotFoundError('No Incident found');

 

 

I attempted the following options and nothing came out:

 

gs.info(err); // Outputs [Object NotFoundError]

gs.info(JSON.stringify(err)); // Outputs nothing

gs.info(Object.keys(err)); // Outputs nothing

for (var k in err) { // This does not even execute
  gs.info(k);
  gs.info(err[k])
}

 

 

I know one of the errors has the following methods:

 

var myError = new sn_ws_err.ServiceError();
myError.setStatus(442);
myError.setMessage('Some Message');
myError.setDetail('Some details.');

 

 

Has anyone managed to find how to retrieve status/message/detail out of the generated object?

 

Reason: there is code inside ServiceNow that makes use of these calls, and fails to return a sensible message when those functions are called. So it makes it really hard to log, or diverge behavior if those issues are found.

 

Thanks

4 REPLIES 4

tfloyd
Tera Contributor

Hey rdelpeso1,

 

From a scripted rest api rest resource, I've used error setting like this:


response.setError(new sn_ws_err.BadRequestError("No Matching rules found"));

return;

 

This yields a response result like this:

 
{
    "error": {
        "message""No Matching rules found",
        "detail"""
    },
    "status""failure"
}
 
This is pretty generic and I haven't tried setting additional details or changing the status message here, but see if BadRequestError gets you where you want to go.
 
Thanks,
Tyler

lakakhan
Tera Contributor

"API" stands for "Application Programming Interface," and it refers to a set of rules and protocols that allow different software programs to communicate with each other. An API defines how to access a specific service or application and how to use its functionality.

The "new" keyword in programming languages like JavaScript, C# and Java is used to create a new instance of an object or class. When the "new" keyword is used in combination with a constructor function, it creates a new object with the properties and methods defined in the constructor.

Property Management Software 

Example:

 

 


@rdelpeso1 wrote:

Hi,

 

Has anyone figured out the API for new sn_ws_err.NotFoundError to grab the message/status that it holds inside?

 

example:

 

 

var err = new sn_ws_err.NotFoundError('No Incident found');

 

 

 

I attempted the following options and nothing came out:

 

 

gs.info(err); // Outputs [Object NotFoundError]

gs.info(JSON.stringify(err)); // Outputs nothing

gs.info(Object.keys(err)); // Outputs nothing

for (var k in err) { // This does not even execute
  gs.info(k);
  gs.info(err[k])
}

 

 

 

I know one of the errors has the following methods:

 

 

var myError = new sn_ws_err.ServiceError();
myError.setStatus(442);
myError.setMessage('Some Message');
myError.setDetail('Some details.');

 

 

 

Has anyone managed to find how to retrieve status/message/detail out of the generated object?

 

Reason: there is code inside ServiceNow that makes use of these calls, and fails to return a sensible message when those functions are called. So it makes it really hard to log, or diverge behavior if those issues are found.

 

Thanks



class MyClass {
constructor(param1, param2) {
this.param1 = param1;
this.param2 = param2;
}
}

const myObject = new MyClass("value1", "value2");
console.log(myObject.param1); // Output: "value1"
console.log(myObject.param2); // Output: "value2"

pickleballcloud
Kilo Contributor

"Programming interface" means "Application Programming Point of interaction," and it alludes to a bunch of decides and conventions that permit different programming projects to speak with one another. A Programming interface characterizes how to get to a particular help or application and how to utilize its usefulness. The "new" watchword in programming dialects like JavaScript, C# and Java is utilized to make another occasion of an article or class. When the "new" watchword is utilized in mix with a constructor capability, it makes another item with the properties and strategies characterized in the constructor. 

James Fricker
Tera Guru

All of the methods of sn_ws_err.ServiceError return the source object (this) to allow for method chaining. This is a standard javascript paradigm.

https://lual.dev/blog/js-method-chaining/