str.replace is not a function
See original GitHub issueUsing 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:
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since you post form data try to use the
form
option like in this example instead ofbody
and drop the'Content-Type'
header because it is added automatically then. Does this work?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.