1

I am writing a Cosmos DB post-trigger (NOT the Azure Function Trigger kind but the in-server JS one). In this trigger, I need to access the etag header generated in the response. The trigger works fine except when I add the following code :

    // Retrieve item's new etag from the response
    var newETag = __.response.getValue("etag");

This code causes the request to fail with the following exception : "Unable to get property 'value' of undefined or null reference at getValueInternal". I checked that the response is not null and that the getValue function exists and in fact the exception is thrown from within the getValue function because the property for etag does not exist.

The doc (found here) however states that:

getValue(key) → {string} Gets a specified response header value.

And other doc (found here) also states that:

The following response headers are common to all responses from the SQL API: ... etag (The etag header [...] has the same value as the _etag property in the response body.)...

Now I also DID confirm that I could indeed access the etag from the __.response.getBody() but I cannot rely on that option because my requests are made with the EnableContentResponseOnWrite = false option in which case the response body is null.

Can someone help me figure out what I am missing or doing wrong here ?

Gilles jr Bisson
  • 449
  • 4
  • 11
  • You need to set EnableContentResponseOnWrite = true if you want to get anything back in the response object. – Mark Brown Sep 22 '21 at 17:57
  • @MarkBrown I believe this flag only applies to the body. Because the headers are actually sent back even with EnableContentResponseOnWrite = false... But nevertheless, I tried with EnableContentResponseOnWrite = true and I get the same exception. – Gilles jr Bisson Sep 23 '21 at 02:39

0 Answers0