question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

str.replace is not a function

See original GitHub issue

Using this code:

 const options = {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
                json: true,
                uri: this.config.peachPaymentsUrl + `v1/checkouts`,
                body: {
                    'authentication': {
                        'userId': this.config.peachPaymentsUsername,
                        'password': this.config.peachPaymentsPassword,
                        'entityId': this.config.peachPaymentsAdhocPaymentChannelId
                    },
                    'amount': mathHelper.getCentsAsRandsString(cents),
                    'currency': 'ZAR',
                    'description': 'Ekaya VIP',
                    'paymentType': 'DB' } //debit
            };

const response = await request(options);

Gives the error str.replace is not a function. If I remove the headers line the error goes away.

You can see what is happening in the depths of the request-promise code: untitled

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

21reactions
analog-nicocommented, Jul 6, 2016

Since you post form data try to use the form option like in this example instead of body and drop the 'Content-Type' header because it is added automatically then. Does this work?

9reactions
RichardJECookecommented, Jul 6, 2016

Thanks, that works. But the problem is not that I’m using the API incorrectly, but rather when I do it gives me no error other than : ‘str.replace is not a function’ with no stack trace and no advice on what to fix. This bug is that the error isn’t handled properly and a message given to the user. That inner function shouldn’t be trying to call replace on something that isn’t a string.

Read more comments on GitHub >

github_iconTop Results From Across the Web

var.replace is not a function - javascript
make sure you are passing string to "replace" method. Had same issue and solved it by passing string.
Read more >
TypeError: replace is not a function in JavaScript
TypeError: .replace is not a function occurs when we call replace() function on object which is not an string. replace() function can be...
Read more >
Content.replace is not a function (Example)
The "Content.replace is not a function" just means that the "fileContents" argument isn't a string, which could be something that doesn't even ...
Read more >
String.prototype.replaceAll() - JavaScript - MDN Web Docs
Can be a string or a function. The replacement has the same semantics as that of String.prototype.replace() . Return value. A ...
Read more >
JavaScript String replace() Method
The replace() method searches a string for a value or a regular expression. The replace() method returns a new string with the value(s)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found