• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

포스트가 존재하지 않습니다 에러가 납니다ㅠㅜㅠ

20.04.17 14:53 작성 조회수 128

0

if(!post)에서 걸려서 404에러가 나요ㅠㅠ

console.log(post)찍어봐도 null이 나옵니다. 디비에는 잘 들어가 있는데 어디가 문제일까요??

답변 5

·

답변을 작성해보세요.

0

해결되었어요!! 감사합니다!!!!

0

$%7Bdata.postId%7D

주소에 이 문자열이 끼어있는데 이 부분 프론트에서 잘못 전송된 것 아닌가요? saga 확인해보세요. axios 부분요.

0

if문을 지우고 실행했더니 id 가 null이라고 나옵니다. 혹시 디비 자체에서 문제가 발생한 걸까요?? 

0

콘솔창에러메세지와

POST http://localhost:3065/api/post/$%7Bdata.postId%7D/comment 404 (Not Found)

코드입니다


router.post('/:id/comment',async(req,res,next)=>{
try{
if(!req.user){
return res.status(401).send('로그인이 필요합니다.');
}
const post = await db.Post.findOne({ where: { id: req.params.id } });
if(!post){
return res.status(404).send('포스트가 존재하지 않습니다.');
}
const newComment = await db.Comment.create({
PostId: post.id,
UserId:req.user.id,
content: req.body.content,
});
await post.addComment(newComment.id);
const comment = await db.Comment.findOne({
where:{
id:newComment.id,
},
include:[{
model:db.User,
attributes:['id','nickname'],
}],
});
return res.json(comment);
}catch (e){
console.error(e);
return next(e);
}
});

network의 response 메세지 입니다

포스트가 존재하지 않습니다.

0

코드를 보여주세요.