How to send exact errors in REST API inbound without passing the hard coded string value

Sharique Azim
Mega Sage

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.

 

1 ACCEPTED SOLUTION

Sharique Azim
Mega Sage

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.

View solution in original post

6 REPLIES 6

Sharique Azim
Mega Sage

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.

Although marked correct initially, if a better approach is provided. i would mark that response correct.