Closed fora22 closed 3 years ago
통상적으로 HTTPS 응답(?)에서 404 Error 를 많이 본적이 있습니다. 저희 Swagger 를 통해 정상작동하면 200 응답을 에러시 400 응답을 하도록 했는데 이는 router 에서 변수를 send() 한건가요? 아니면 자동적으로 Promise 객체에 응답 숫자가 있는건가요?
send()
https://github.com/JEoN-Ha/Senior-Project/blob/bf1acb1163fe2132c35424a40351cd79e3c4965e/jiyeon/jeonha_redux/public/swagger.yaml#L13-L69
예를 들어 위 api 명세서에 따라
router.post('/signUp', (req, res) => { const userwebid = `'${req.body.userWebId}'`; const username = `'${req.body.userName}'`; const pw = `'${req.body.pw}'`; const phonenum = `'${req.body.phoneNum}'`; const carid = `'${req.body.carId}'`; const sqlCodeToUserTable = ` insert into usertable(UserWebId, UserName, PW, PhoneNum) values (${userwebid}, ${username}, ${pw}, ${carid}) `; let idOverlap = true; let pwOverlap = true; let dbError = true; db.query(sqlCodeToUserTable, (err, rows) => { if(err) { idOverlap = false; pwOverlap = false; } }) const sqlCodeToCarTable = ` insert into car(CarWebId, CarId) values (${userwebid}, ${carid}) `; db.query(sqlCodeToCarTable, (err, rows) => { if(err) { errorCheck = false; } }) if (errorCheck) { res.send('200'); } else { res.send('400'); } })
이렇게 send()로 보내줘야 하나요??
이렇게 하면 body의 값 자체가 200, 400이 되기 때문에 statusCode에 값을 넣어서 보내야 합니다.
https://nodejs.org/api/http.html#http_response_statuscode
이렇게 하면 body의 값 자체가 200, 400이 되기 때문에 statusCode에 값을 넣어서 보내야 합니다. https://nodejs.org/api/http.html#http_response_statuscode
아 statusCode 가 있군요. 하면서 계속 뭔가 이상하다 싶었습니다. ㅎㅎㅎㅎ 감사합니다!
statusCode
@kiJiyeon 의문 해결!
통상적으로 HTTPS 응답(?)에서 404 Error 를 많이 본적이 있습니다. 저희 Swagger 를 통해 정상작동하면 200 응답을 에러시 400 응답을 하도록 했는데 이는 router 에서 변수를
send()
한건가요? 아니면 자동적으로 Promise 객체에 응답 숫자가 있는건가요?https://github.com/JEoN-Ha/Senior-Project/blob/bf1acb1163fe2132c35424a40351cd79e3c4965e/jiyeon/jeonha_redux/public/swagger.yaml#L13-L69
예를 들어 위 api 명세서에 따라
이렇게
send()
로 보내줘야 하나요??