serverless event.body был объектом, но тип содержимого не является json - PullRequest
0 голосов
/ 11 декабря 2018

я использую без сервера для развертывания моего API;

functions:
  # hello:
  #   handler: index.handler
  #   events:
  #     - http: ANY /
  #     - http: 'ANY {proxy+}'
  addAnnouncement:
    handler: index.handler
    events:
      - http:
          method: POST
          path: /abc/{foo}/cde/efg
          cors: true
          integration: lambda
          request:
            parameters:
              paths:
                foo: true
      - http:
          method: DELETE
          path: /abc/{foo}/cde/efg
          cors: true
          integration: lambda
          request:
            parameters:
              paths:
                foo: true
      - http:
          method: GET
          path: /abc/{foo}/cde/efg
          cors: true
          integration: lambda
          request:
            parameters:
              paths:
                foo: true

мои маршруты API выглядят так;

получить следующую ошибку, когда я нажму api-gateway-url

{
  "errorMessage": "event.body was an object but content-type is not json",
  "errorType": "Error",
  "stackTrace": [
  "getBody (/var/task/node_modules/serverless-http/lib/request.js:24:13)",
  "new ServerlessRequest (/var/task/node_modules/serverless-http/lib/request.js:44:18)",
  "Promise.resolve.then (/var/task/node_modules/serverless-http/serverless-http.js:30:25)",
"<anonymous>"
]
}
...