- 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 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 10:27 PM
Although marked correct initially, if a better approach is provided. i would mark that response correct.