-
카테고리
-
세부 분야
풀스택
-
해결 여부
해결됨
동작 오류 질문입니다.
20.01.15 17:35 작성 조회수 339
0
팔로우 언팔로우 기능이 안되서 확인해보니
네트워크 탭에 SequelizeUniqueConstraintError: Validation error
at Query.formatError (C:\Users\Desktop\react-nodebird\back\node_modules\sequelize\lib\dialects\mysql\query.js:223:16)
at Query.handler [as onResult] (C:\Users\Desktop\react-nodebird\back\node_modules\sequelize\lib\dialects\mysql\query.js:51:23)
at Query.execute (C:\Users\Desktop\react-nodebird\back\node_modules\mysql2\lib\commands\command.js:30:14)
at Connection.handlePacket (C:\Users\Desktop\react-nodebird\back\node_modules\mysql2\lib\connection.js:417:32)
at PacketParser.Connection.packetParser.p [as onPacket] (C:\Users\Desktop\react-nodebird\back\node_modules\mysql2\lib\connection.js:75:12)
at PacketParser.executeStart (C:\Users\Desktop\react-nodebird\back\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.Connection.stream.on.data (C:\Users\Desktop\react-nodebird\back\node_modules\mysql2\lib\connection.js:82:25)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
위에 내용과 같이 출력됩니다. 리덕스에서 팔로우 클릭시 FOLLOW_USER_FAULURE라고 출력됩니다.
답변을 작성해보세요.
0
조현영
지식공유자2020.01.16
axios.get과 axios.delete는 데이터가 없습니다(요청의 body가 없습니다) 그래서 두 번째 인수는 데이터가 아니라 옵션 객체입니다. post와 put patch는 두 번째 인수가 데이터고 세 번째 인수가 옵션입니다.
0
s s
질문자2020.01.16
오류의 원인을 찾았습니다
//언팔로우
function unfollowAPI(userId) {
// 서버에 요청을 보내는 부분
return axios.delete(`/user/${userId}/follow`, {}, {
withCredentials: true,
});
}
//팔로우
function followAPI(userId) {
// 서버에 요청을 보내는 부분
return axios.post(`/user/${userId}/follow`, {}, {
withCredentials: true,
});
}
이 부분에서 unfollowAPI의 axios.delete 부분의 {} 이부분이 문제가 있었네요 데이터 보내는게 없어도 빈 배열로 데이터
보내야 되는줄 알았는데 unfollow쪽에 저렇게 보내면 에러가 출력되더라고요 이유가 뭔가요??
0
0
s s
질문자2020.01.15
이부분 말씀하시는건가요? 해줬습니다.
//언팔로우
function unfollowAPI(userId) {
// 서버에 요청을 보내는 부분
return axios.delete(`/user/${userId}/follow`, {}, {
withCredentials: true,
});
}
//팔로우
function followAPI(userId) {
// 서버에 요청을 보내는 부분
return axios.post(`/user/${userId}/follow`, {}, {
withCredentials: true,
});
}
0
0
s s
질문자2020.01.15
로그인이 되어있는 상태인데 로그인이 필요합니다라고 출력되네요.
reducers/user.js 의 소스입니다.
case FOLLOW_USER_REQUEST: {
return {
...state,
};
}
case FOLLOW_USER_SUCCESS: {
return {
...state,
me: {
...state.me,
Followings: [{ id: action.data }, ...state.me.Followings],
},
};
}
case FOLLOW_USER_FAILURE: {
return {
...state,
};
}
case UNFOLLOW_USER_REQUEST: {
return {
...state,
};
}
case UNFOLLOW_USER_SUCCESS: {
return {
...state,
me: {
...state.me,
// Followings: [...state.me.Followings].filter(v => v.id !== action.data),
Followings: state.me.Followings.filter(v => v.id !== action.data),
},
};
}
case UNFOLLOW_USER_FAILURE: {
return {
...state,
};
}
sagas/user.js의 소스입니다.
//=============================================
//팔로우
function followAPI(userId) {
// 서버에 요청을 보내는 부분
return axios.post(`/user/${userId}/follow`, {}, {
withCredentials: true,
});
}
function* follow(action) {
try {
// yield call(loadUserAPI);
const result = yield call(followAPI, action.data);
yield put({ // put은 dispatch 동일
type: FOLLOW_USER_SUCCESS,
data: result.data,
});
} catch (e) { // loginAPI 실패
console.error(e);
yield put({
type: FOLLOW_USER_FAILURE,
error: e,
});
}
}
function* watchFollow() {
yield takeEvery(FOLLOW_USER_REQUEST, follow);
}
//=============================================
//언팔로우
function unfollowAPI(userId) {
// 서버에 요청을 보내는 부분
return axios.delete(`/user/${userId}/follow`, {}, {
withCredentials: true,
});
}
function* unfollow(action) {
try {
// yield call(loadUserAPI);
const result = yield call(unfollowAPI, action.data);
yield put({ // put은 dispatch 동일
type: UNFOLLOW_USER_SUCCESS,
data: result.data,
});
} catch (e) { // loginAPI 실패
console.error(e);
yield put({
type: UNFOLLOW_USER_FAILURE,
error: e,
});
}
}
function* watchUnfollow() {
yield takeEvery(UNFOLLOW_USER_REQUEST, unfollow);
}
back/routes/user.js의 소스입니다.
router.post('/:id/follow', isLoggedIn, async (req, res, next) => {
try {
const me = await db.User.findOne({
where: { id: req.user.id },
});
await me.addFollowing(req.params.id);
res.send(req.params.id);
} catch (e) {
console.error(e);
next(e);
}
});
router.delete('/:id/follow', isLoggedIn, async (req, res, next) => {
try {
const me = await db.User.findOne({
where: { id: req.user.id },
});
await me.removeFollowing(req.params.id);
res.send(req.params.id);
} catch (e) {
console.error(e);
next(e);
}
});
0
답변 7