• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

데이터 베이스 생성 후 postman의 get products에서 send를 누른 뒤 오류

22.07.24 15:04 작성 조회수 551

2

안녕하세요 그랩님! 강의 잘 듣고 있습니다.

postman에서 create product에서 제품 정보들을 입력하고, DB Browser for SQLite에 데이터가 아래와 같이 입력된 것을 확인했습니다.

이후 포스트맨에서 get products로 들어가 send를 누르니 아래와 같이 '모든 필드를 입력해주세요' 라는 문구가 뜹니다. 

vscode에서 name, description,price,seller 이 네가지가 notNull로 설정되어 있어서

이 네가지 값이 잘 입력되지 않았을 때 해당 에러 문구가 뜨는 것일 텐데

소스 코드를 보면서 다른 점을 찾아봐도 딱히 다른점을 모르겠습니다... (제 눈의 문제인지...ㅠㅠ)

아래는 제가 작성한 코드입니다.

 

<product.js>

 

<server.js>

 

vscode 터미널에 뜨는 에러 코드는 아래와 같습니다. 

에러 코드에도 보면 첫줄에 'notNull Violation'이라고 되어 있어서 해당 조건을 어겼기 때문인 것 같은데...

데이터 베이스에 값들이 잘 들어가 있는 거 같은데 뭐가 잘못된 걸까요... 

한 번 봐주시고 혹시 제가 놓친 부분이 있거나 좋은 방법이 있다면 답변해주시면 감사하겠습니다..!! 

 

ValidationError [SequelizeValidationError]: notNull Violation: Product.name cannot be null,
notNull Violation: Product.price cannot be null,
notNull Violation: Product.seller cannot be null,
notNull Violation: Product.description cannot be null
    at InstanceValidator._validate (/Users/jade/Desktop/grab-market-server/node_modules/sequelize/lib/instance-validator.js:50:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async InstanceValidator._validateAndRunHooks (/Users/jade/Desktop/grab-market-server/node_modules/sequelize/lib/instance-validator.js:60:7)
    at async InstanceValidator.validate (/Users/jade/Desktop/grab-market-server/node_modules/sequelize/lib/instance-validator.js:54:12)
    at async model.save (/Users/jade/Desktop/grab-market-server/node_modules/sequelize/lib/model.js:2368:7)
    at async Function.create (/Users/jade/Desktop/grab-market-server/node_modules/sequelize/lib/model.js:1344:12) {
  errors: [
    ValidationErrorItem {
      message: 'Product.name cannot be null',
      type: 'notNull Violation',
      path: 'name',
      value: null,
      origin: 'CORE',
      instance: [Product],
      validatorKey: 'is_null',
      validatorName: null,
      validatorArgs: []
    },
    ValidationErrorItem {
      message: 'Product.price cannot be null',
      type: 'notNull Violation',
      path: 'price',
      value: null,
      origin: 'CORE',
      instance: [Product],
      validatorKey: 'is_null',
      validatorName: null,
      validatorArgs: []
    },
    ValidationErrorItem {
      message: 'Product.seller cannot be null',
      type: 'notNull Violation',
      path: 'seller',
      value: null,
      origin: 'CORE',
      instance: [Product],
      validatorKey: 'is_null',
      validatorName: null,
      validatorArgs: []
    },
    ValidationErrorItem {
      message: 'Product.description cannot be null',
      type: 'notNull Violation',
      path: 'description',
      value: null,
      origin: 'CORE',
      instance: [Product],
      validatorKey: 'is_null',
      validatorName: null,
      validatorArgs: []
    }
  ]
}
node:internal/errors:465
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (node:internal/errors:372:5)
    at ServerResponse.setHeader (node:_http_outgoing:576:11)
    at ServerResponse.header (/Users/jade/Desktop/grab-market-server/node_modules/express/lib/response.js:794:10)
    at ServerResponse.send (/Users/jade/Desktop/grab-market-server/node_modules/express/lib/response.js:174:12)
    at /Users/jade/Desktop/grab-market-server/server.js:44:11
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

 

답변 2

·

답변을 작성해보세요.

1

tucm88님의 프로필

tucm88

2022.07.26

postman에서 send를 할 때 앞쪽에 있는 POST를 GET으로 바꾸고 send를 했어야 했네요...ㅎㅎ.. 해결되었습니다..!!! 

0

처음에 HTTP Method를 헷갈리는 경우가 많은데 잘 찾으셨네요! 화이팅입니다 :)