serverless-offline icon indicating copy to clipboard operation
serverless-offline copied to clipboard

TypeError: Cannot destructure property 'responseParameters' of 'chosenResponse' as it is undefined

Open Hiroki111 opened this issue 1 year ago • 2 comments

Bug Report

Running a serverless app with "sls offline" and making a request to the app's REST API endpoint results in the following message:

Debug: internal, implementation, error 
    TypeError: Cannot destructure property 'responseParameters' of 'chosenResponse' as it is undefined.
    at file:///home/app/sls-offline-debug/node_modules/serverless-offline/src/events/http/HttpServer.js:657:15
    at async exports.Manager.execute (/home/app/sls-offline-debug/node_modules/@hapi/hapi/lib/toolkit.js:60:28)
    at async Object.internals.handler (/home/app/sls-offline-debug/node_modules/@hapi/hapi/lib/handler.js:46:20)
    at async exports.execute (/home/app/sls-offline-debug/node_modules/@hapi/hapi/lib/handler.js:31:20)
    at async Request._lifecycle (/home/app/sls-offline-debug/node_modules/@hapi/hapi/lib/request.js:370:32)
    at async Request._execute (/home/app/sls-offline-debug/node_modules/@hapi/hapi/lib/request.js:280:9)

Screenshot 2023-04-09 172032

(If I click "http://localhost:3000/dev/products" on the console, I see the error message above on the console)

Current Behavior

Just described above

Sample Code

I've made a repo for this error: https://github.com/Hiroki111/sls-offline-debug

If you run this app by "sls offline", you should be able to see the same error.

Expected behavior/code

"GET | http://localhost:3000/dev/products" return an array of object and the status code is 200.

Environment

  • serverless version: [v3.26.0]
  • serverless-offline version: [^12.0.4]
  • node.js version: [e.g. v16.14.2]
  • OS: [Ubuntu 20.04 (WSL2)]

Possible Solution

Additional context/Screenshots

Hiroki111 avatar Apr 09 '23 15:04 Hiroki111

I think this problem is related to the use of.

        responses: {
          200: {
            description: 'This is a success response',
            bodyType: 'Product',
          },
        },

where did you find this in the serverless documentation?

Denis-String avatar Jul 03 '23 18:07 Denis-String

Workaround:

Adding default response

responses: {
          default: {},
          200: {
            description: 'This is a success response',
            bodyType: 'Product',
          },
        },

matricali avatar Nov 07 '23 16:11 matricali

@Hiroki111 Fixed in v13.3.4

DorianMazur avatar Apr 19 '24 15:04 DorianMazur