apostopher
apostopher

Reputation: 293

javascript extension error: Cannot perform modifications

I'm building a custom dynamicValue extension for paw. However i'm not able to set header in the evaluate method. See the sample code below:

evaluate(context) {
  const request = context.getCurrentRequest();
  request.setHeader('Content-Type', this.contentType); // <-- this gives warning
  return this.createSignable(request); // This returns a base64 string.
}

I get the warning saying Javascript extension error: Cannot perform modifications and the header is not set. ( when i comment out request.setHeader call, i get no warnings) enter image description here Can anyone please help me resolve this issue?

Upvotes: 2

Views: 63

Answers (1)

Micha Mazaheri
Micha Mazaheri

Reputation: 3481

This is correct, you cannot use setters (set any value) in a dynamic value. In fact, the way Paw evaluates dynamic values is asynchronous and as multiple evaluations can take place simultaneously it would be impossible to record the modifications. For this reason, Paw is simply denying changes and no change is persisted during evaluation.

In the documentation, it's specified that these methods (like setHeaders) is only available for importer extensions. Sorry for the inconvenience!

I think to achieve what you're trying to do, you would need two dynamic values one set in the Authorization header and one set in the Content-Type header.

Alternatively, in the future we're going to add request post-processors, so you'll be able to mutate the computed request ready to be sent to the server for additional modifications.

Upvotes: 1

Related Questions