swsnu / swppfall2020

28 stars 17 forks source link

[HW4] 400 Bad Request 처리 #161

Open ariadne240 opened 4 years ago

ariadne240 commented 4 years ago

README에서는 400을 처리해야 한다는 말이 없는 것 같은데, 혹시 body에 적절한 key가 들어오지 않았을 경우를 대비해서 400 Bad Request를 처리해 주어야 하나요?

kooyunmo commented 4 years ago

해당 부분에 대해서 따로 테스트를 하지는 않겠지만 실습 시간에 배운 것과 같이 400(Bad request)처리를 해주시면 좋습니다. (이 부분에 대해서 따로 테스트를 하지 않는 이유는 json content에 대해서 frontend level에서 validation이 가능하기 때문입니다.)

try:
     # decode body and read value from key
except (JSONDecodeError, KeyError):
     return HttpResponseBadRequest()

처리시 우선 순위를 따진다면 다음과 같이 처리해 주시기 바랍니다.

  1. 먼저 해당 article (혹은 comment)이 있는지 찾는다 --> 없으면 404
  2. article (혹은 comment)이 있으면 PUT이나 POST에 대해서 request content를 가져오고, 필요한 key로부터 value를 읽는다 --> 이 과정에서 문제가 있으면 400
ariadne240 commented 4 years ago

감사합니다.