Why am I not able to see the response headers even though I am setting them in Javascript code under Fault/Error Flow ?

I have an API Proxy, where none of the target endpoints gets selected because of the conditions applied. Eventually I get an Error as expected. I have setup Javascript policy to be executed in the Error flow, where I setup a few headers in the response object as shown below:

var startTime = context.getVariable('client.received.start.timestamp');
var endTime = context.getVariable('system.timestamp');
var requestDuration = (endTime - startTime).toString();

context.setVariable('response.header.X-WF.Request-Duration', requestDuration);

When I enable the trace, I am able to see that the Javascript policy does get executed. But I don’t see the above header in the response that is sent back to the client.

Solved Solved
0 3 577
1 ACCEPTED SOLUTION

After some investigation, I figured out that response object will not be available in the error flow. Instead we will have access to the error object. So we can set the header in the error object as follows:

context.setVariable("error.header.X-WF.Request-Duration", requestDuration);

With this change, I was able to see the header as part of the response sent to the client.

View solution in original post

3 REPLIES 3

After some investigation, I figured out that response object will not be available in the error flow. Instead we will have access to the error object. So we can set the header in the error object as follows:

context.setVariable("error.header.X-WF.Request-Duration", requestDuration);

With this change, I was able to see the header as part of the response sent to the client.

adas
New Member

If you simply do:

context.setVariable("response.header.X-WF.Request-Duration", requestDuration);

that should work as well. Is that not working for you ?

@arghya das,

Infact, that's what I had tried, it doesn't work. I had made a typo mistake when I posted the question. I have corrected it now.