RESTful - Error Response Limit?

The forum to discuss the Headless version of Servoy. Web, Java and Servlet development questions can all be posted here.

RESTful - Error Response Limit?

Postby bcusick » Fri Feb 24, 2017 7:09 pm

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:
Code: Select all
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:
Code: Select all
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
Bob Cusick
bcusick
 
Posts: 1183
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Re: RESTful - Error Response Limit?

Postby bcusick » Fri Feb 24, 2017 7:16 pm

OK - got it!

I was concatenating stuff to make up the message:

Code: Select all
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:

Code: Select all
throw[400, sErr.toString()];
Bob Cusick
bcusick
 
Posts: 1183
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA


Return to Servoy Headless Client

Who is online

Users browsing this forum: No registered users and 1 guest