RESTful - Error Response Limit?

Hey Guys,

In working with the RESTful plugin - I want to add a message to the error that’s returned.

I’m looking at the docs: https://wiki.servoy.com/display/public/DOCS/RESTful+Web+Services

It says:

It is also possible to set the body content of the HTTP Response with a more elaborate message to give more context to the returned status code:

function ws_update(){
//your logic here
var code = plugins.http.HTTP_STATUS.SC_UNAUTHORIZED
var message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><error><reason>access denied</reason><message>access token is expired</message></error>"
throw [code, message];

}

I’m trying this code:

if( blah ){
  throw [400, "Invalid URL parameter. The ID you passed: 'E24BBA6C-1B7F-4B37-97C-9E3071E24FDC' was too short it should be a UUID with a length of 36 (ie: 98AD9A2D-6BE3-468B-A8F7-F099DE6FCE1E)"];
}

I"m getting the error: “org.mozilla.javascript.CharSequenceBuffer cannot be cast to java.lang.String”

Servoy 7.4.9
Windows 10
Java 1.8.0_121

Thanks in advance!

Bob

OK - got it!

I was concatenating stuff to make up the message:

sErr = "Invalid URL parameter. One of the IDs you passed " + oObj.rec_id[i] + " was too short it should be a UUID with a length of 36";

That is OK - but when you throw the error - you have to cast it as a string:

throw[400, sErr.toString()];