gstroup / apimocker

node.js module to run a simple http server for mock service responses.
MIT License
280 stars 81 forks source link

Apimocker crashes when mockFile is missing #21

Closed platan closed 9 years ago

platan commented 9 years ago

Apimocker (v.0.4.0) crashes when required element mockFile is missing for webservice:

{
    "mockDirectory": "/home/me/apimocker",
    "quiet": false,
    "port": "8300",
    "webServices": {
        "items/1": {
            "verbs": ["get"]
        }
    }
}
$ apimocker -c config.json
Loading config file: /home/me/apimocker/config.json
Set route: GET items/1 : <no mockFile> 
Mock server listening on port 8300
curl -v localhost:8300/items/1                                                                                                                    ⏎
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8300 (#0)
> GET /items/1 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8300
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
path.js:360
        throw new TypeError('Arguments to path.join must be strings');
              ^
TypeError: Arguments to path.join must be strings
    at path.js:360:15
    at Array.filter (native)
    at Object.exports.join (path.js:358:36)
    at null._onTimeout (/usr/lib/node_modules/apimocker/lib/apimocker.js:151:21)
    at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)

Maybe it should return 5xx server error HTTP status code insted?

gstroup commented 9 years ago

Good suggestion - it should probably return a 500 error. This seems like a fix that would be pretty simple. I'm pretty busy right now, but I'll try to get it in soon. Also, pull requests are welcome!

gstroup commented 9 years ago

Fixed in apimocker v0.4.1.