1.2k questions

1.4k answers

361 comments

339 users

Categories

Sidebar
0 votes
872 views
by (240 points)
It seems like every request made to QIE gets a response back with an HTTP status code of 200 or 500.  Is there a way to manually set the HTTP status code on responses.  For instance, if I wanted to return 400 series codes for request/auth issues.  Or if I wanted to just manually return a 500 without relying on the underlying QIE code failing.

1 Answer

+1 vote
 
Best answer

You can add the following options to the start of the response:

var response = "HTTP Status: 404\r\n";
response += "http.header.Content-Type=text/plain\r\n";
response += "http.header.myToken=ABCDEF\r\n";
response += "\r\n";
response += "This is my payload";

qie.postMessageResponse(response);

The HTTP Status can return any integer value for the status code.

The Content-Type allows you to specify the payload content type.

The http header can be any additional headers that are needed in the response.  To specify a header, you will prefix the header name with "http.header.", separate the header name (key) and the value with a colon (=), and end with a carriage return line feed (\r\n).

 

Make sure that you have set your source node to response to "From Mapping or Destination node"

 

You can create a custom mapping function withe the qie.postMessageResponse(response);

 

See also:

Handling HTTP requests and responses

Posting Responses via qie.postMessageResponse() in a channel that uses an HTTP Listener source node

by ben-s-7515 (13.0k points)
edited by rich-c-2789
by golden-m-1060 (120 points)
I'm using this to check an api token in the first step of my mapping function.  If the api-token isn't valid I'm posting the message response as shown above, but how can I stop processing at that point?  If I use a return statement, (at least in test mode) the rest of the mapping function executes.
...