- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2018 12:36 AM
Can some one kindly instruct me ,how to send error in responses,whenever you get any bad request WITHOUT giving the same string message?
For example:
{
"error": {
"message": "The undefined value has no properties.",
"detail": "ConversionError: The undefined value has no properties. (sys_ws_operation.e76abaa11b0a6300de0efcccdd4bcb4d.operation_script; line 23)"
},
"status": "failure"
}
Now,incase this has some other error reasons, i would like to send in the exact message and details. and not some generic message.
Please note: i have gone through Scripted REST API error objects and related docs before raising this post.
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2018 10:26 PM
I found out a way to send out the error message. Doesnt works directy like in Docs(most probably due to scope issues)
For those intrested:
var bdy=request.body.data;
try{
//some logic}
catch(e){
var err=JSON.stringify(e);
var req_bdy =JSON.stringify(bdy);
response.setContentType('application/json');
var resp=response.getStreamWriter(),
hdrs = {};
hdrs['Content-Type'] = 'application/json';
response.setStatus(400);
response.setHeaders(hdrs);
resp.writeString("{\"results\":[");
resp.writeString(err);
resp.writeString("]}");
gs.info('POST BAD request:'+req_bdy.toString()+'\nError:'+err);
}
For some reasons, i was not able to use object serializing method here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2018 12:42 AM
Hello,
You could add your script in a try catch block and fetch errors and send it back in your response. This will give you the exact error message associated with the script execution.
try{
//Your script here
}catch(error e){
//Setup required error message or format
response.error = "Caught error: "+e;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2018 10:20 PM
Doesnt works.
most probably response.error is not a function but response.setError is.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2018 02:03 AM
Hello Shariq,
Just out of curiosity what i wanted to know is the reason you are looking for exact errors instead of customized errors which will be user friendly for the end users with the oob Service Error object
Thanks,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2018 10:21 PM
Customized also means knowing what was the issue/error sending response accordingly.