snapstub icon indicating copy to clipboard operation
snapstub copied to clipboard

Status code 204 not handled

Open MasterATM opened this issue 3 years ago • 0 comments

Hello, When a request (giving a HTTP 204) is recorded, the resulting file looks like: get-bbf8b8270b12be24192d49e1363a9e936e11d94332d0bf02d594e731023c9f8c.json

and its content is empty. Whenever stubborn serves this file, it gets an exception as it tries to parse the content thinking it is json (I had to put some console.logs in stubborn to uncover this stack trace). In the end, a HTTP 404 is sent back to the client.

SyntaxError: C:\dev\__mocks__\get-bbf8b8270b12be24192d49e1363a9e936e11d94332d0bf02d594e731023c9f8c.json: Unexpected end of JSON input
    at parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:1128:22)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at Module.hijacked [as require] (C:\dev\node_modules\stubborn-server\server\force-require.js:14:28)
    at require (internal/modules/cjs/helpers.js:92:18)
    at hashLoader (C:\dev\node_modules\stubborn-server-hash-loader\lib\index.js:27:17)
    at C:\dev\node_modules\stubborn-server\server\path-resolver.js:24:34
    at Array.reduce (<anonymous>)

I see stubborn has a possibility to have a custom js file to handle the response. If I remove the mock and replace it by: C:\dev_mocks_\get-bbf8b8270b12be24192d49e1363a9e936e11d94332d0bf02d594e731023c9f8c.js with this content:

module.exports = (req, res, stub) => {
  res.status(204).send();
};

then my webapp receives the HTTP 204.

Do you think it would be possible to have this in snapstub? Thanks.

MasterATM avatar Sep 30 '21 13:09 MasterATM