1
resposta

TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined.

Quando eu dou o post no no Postman, recebo esse erro:

(node:39091) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property 'id' of 'undefined' as it is undefined. at new Fornecedor (/home/bruno-programador/Alura/api-petshop/api/rotas/fornecedores/Fornecedor.js:4:17) at /home/bruno-programador/Alura/api-petshop/api/rotas/fornecedores/index.js:14:22 at Layer.handle [as handle_request] (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/layer.js:95:5) at next (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/layer.js:95:5) at /home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/index.js:335:12) at next (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/index.js:275:10) at Function.handle (/home/bruno-programador/Alura/api-petshop/node_modules/express/lib/router/index.js:174:3) (Use node --trace-warnings ... to show where the warning was created) (node:39091) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:39091) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

O que eu estou adicionando no postman: { "empresa": "Alura Ração para Gatos", "email": "vendas@alura.petshop", "categoria": "ração" }

O link do repositório para visualização dos arquivos: https://github.com/brunobastosfer/api_rest_create

Agradeço desde já !

1 resposta

Fala Bruno, beleza?

Tenta colocar o app.use(bodyParser.json()) (linha 9) antes do app.use("/api/fornecedores", roteador) (linha 8) no arquivo https://github.com/brunobastosfer/api_rest_create/blob/main/api/index.js

Acho que resolve.

Qualquer coisa, manda aí!

[]'s