stubby4node icon indicating copy to clipboard operation
stubby4node copied to clipboard

error: string.replace is not a function

Open antoncic opened this issue 8 years ago • 4 comments

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

antoncic avatar Nov 25 '16 12:11 antoncic

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?

cdm319 avatar Feb 16 '17 11:02 cdm319

Thanks for the reply! I will test this.

antoncic avatar Feb 16 '17 12:02 antoncic

@antoncic any luck?

cdm319 avatar Mar 01 '17 16:03 cdm319

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
  }
}

dbomfim avatar Mar 15 '18 19:03 dbomfim