Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: string.replace is not a function #62

Open
antoncic opened this issue Nov 25, 2016 · 4 comments
Open

error: string.replace is not a function #62

antoncic opened this issue Nov 25, 2016 · 4 comments

Comments

@antoncic
Copy link

antoncic commented Nov 25, 2016

Hi,
I'm really struggling with this issue trying to mock a POST request.

12:48:59 -> POST [stubs]/api/gui/clients/123456789/password
12:48:59 <- 500 [stubs]/api/gui/clients/123456789/password unexpectedly generated a server error: string.replace is not a function

I'm running Stubby 4.0.0 with
npm run stubby -- --watch
using Postman to configure Stubby running on OsX 10.11.6
using POST localhost:8889 with body

{
  "request": {
    "url": "/api/gui/clients/123456789/password",
    "method": "POST",
    "headers":{
    	"content-type": "application/json"
    },
    "post": {
    	"currentPassword": "blaha",
    	"newPassword": "23452345"
    }
  },
  "response": {
    "status": 403,
    "latency": 1000
  }
}

The request from my webapplication to stubby looks like this:

Request Headers
POST /api/gui/clients/123456789/password HTTP/1.1
Host: localhost:8882
Connection: keep-alive
Content-Length: 61
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36
Content-Type: application/json
Accept: */*
Referer: http://localhost:8080/settings
Accept-Encoding: gzip, deflate, br
Accept-Language: sv,nb;q=0.8,no;q=0.6,en;q=0.4,en-US;q=0.2

Request Payload
{
  "currentPassword": "blaha",
  "newPassword": "23452345"
}

What can it be? I cannot find anything similar with Stubby when googling.

best regards / Niklas Antoncic

@cdm319
Copy link

cdm319 commented Feb 16, 2017

I have seen the same issue, I believe it's because the documentation shows the request.post value as a string, and you're attempting a raw JSON object. Maybe try using request.json instead?

@antoncic
Copy link
Author

Thanks for the reply! I will test this.

@cdm319
Copy link

cdm319 commented Mar 1, 2017

@antoncic any luck?

@dbomfim
Copy link

dbomfim commented Mar 15, 2018

I had the same error. Try to put the post as string as @cdm319 said:

{
  "request": {
    "url": "/api/gui/clients/123456789/password",
    "method": "POST",
    "headers":{
    	"content-type": "application/json"
    },
    "post": '{"currentPassword": "blaha","newPassword": "23452345"}'
  },
  "response": {
    "status": 403,
    "latency": 1000
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants