Skip to content

Commit a85369a

Browse files
committed
feat: throw new Error 상수화 처리
1 parent c8a858d commit a85369a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

apps/next-client/src/constants/errors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export const ERROR_MESSAGES = {
2121
INVALID_RESPONSE_FORMAT: "API 응답 형식이 올바르지 않습니다. 배열이 아닙니다.",
2222
NO_SEARCH_RESULTS: "검색 결과가 없습니다.",
2323
API_REQUEST_ERROR: "API 요청 중 오류가 발생했습니다.",
24-
CLIENT_ERROR: '잘못된 요청입니다. 다시 시도해주세요.'
24+
CLIENT_ERROR: '잘못된 요청입니다. 다시 시도해주세요.',
25+
PERMISSION_DENIED: "권한이 없습니다.",
26+
EMPTY_FIELDS: "필수 입력 항목이 비어있습니다.",
27+
DELETE_CANCELLED: "삭제가 취소되었습니다."
2528
} as const;
2629

2730
export const FAVORITE_MESSAGES = {

apps/next-client/src/hooks/queries/usePostEdit.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { useSuspenseQuery, useMutation, useQueryClient } from '@tanstack/react-q
44
import { axiosInstance } from '@/services/common/axiosInstance';
55
import { API_URLS } from '@/constants/urls';
66
import { ALERT_MESSAGES } from '@/constants/alertMessage';
7+
import { ERROR_MESSAGES } from '@/constants/errors';
78

89
export const usePostEdit = (id: string, userId: string | undefined, accessToken: string) => {
910
const [title, setTitle] = useState('');
1011
const [content, setContent] = useState('');
1112
const router = useRouter();
1213
const queryClient = useQueryClient();
1314

14-
// 게시글 조회 - useSuspenseQuery 사용 (enabled 옵션 제거)
15+
// 게시글 데이터 가져오기
1516
const { data } = useSuspenseQuery({
1617
queryKey: ['post-edit', id],
1718
queryFn: async () => {
@@ -21,7 +22,7 @@ export const usePostEdit = (id: string, userId: string | undefined, accessToken:
2122
if (post.userId !== userId) {
2223
alert(ALERT_MESSAGES.ERROR.POST.POST_PERMISSION_DENIED);
2324
router.push('/community');
24-
throw new Error('Permission denied');
25+
throw new Error(ERROR_MESSAGES.PERMISSION_DENIED);
2526
}
2627

2728
return post;
@@ -43,7 +44,7 @@ export const usePostEdit = (id: string, userId: string | undefined, accessToken:
4344
mutationFn: async () => {
4445
if (!title.trim() || !content.trim()) {
4546
alert(ALERT_MESSAGES.ERROR.POST.POST_EMPTY_FIELDS);
46-
throw new Error('Empty fields');
47+
throw new Error(ERROR_MESSAGES.EMPTY_FIELDS);
4748
}
4849

4950
return axiosInstance.put(
@@ -67,7 +68,7 @@ export const usePostEdit = (id: string, userId: string | undefined, accessToken:
6768
const deletePostMutation = useMutation({
6869
mutationFn: async () => {
6970
if (!window.confirm(ALERT_MESSAGES.CONFIRM.CHECK_DELETE)) {
70-
throw new Error('Delete cancelled');
71+
throw new Error(ERROR_MESSAGES.DELETE_CANCELLED);
7172
}
7273

7374
return axiosInstance.delete(`${API_URLS.POSTS}/${id}`, {

0 commit comments

Comments
 (0)