Skip to content

Commit 8043c21

Browse files
authored
Refactor/#270-B: 에러 메세지 상수화 및 적용 (#273)
* refactor: server 에러 메세지 상수화 및 적용 Resolve: #270 * refactor: client 에러 메세지 상수화 및 적용 Resolve: #270 * fix: error-message 가 달라서 test 실패 -> CI 실패 에러 해결 * refactor: 오타 수정 * refactor: conflict 해결 * refactor: 오타 수정 적용
1 parent c2982da commit 8043c21

File tree

12 files changed

+51
-21
lines changed

12 files changed

+51
-21
lines changed

client/src/components/WorkspaceModal/CreateSuccessModal.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useNavigate } from 'react-router-dom';
2+
import ERROR_MESSAGE from 'src/constants/error-message';
23
import { Workspace } from 'src/types/workspace';
34

45
import FormModal, { ModalContents } from './FormModal';
@@ -17,7 +18,7 @@ function CreateSuccessModal({
1718
const navigate = useNavigate();
1819

1920
if (!workspace) {
20-
throw new Error('일어날 수 없는 일이 일어났어요 ^^');
21+
throw new Error(ERROR_MESSAGE.IMPOSSIBLE_HAPPENED);
2122
}
2223

2324
const { id, code } = workspace;

client/src/components/WorkspaceSettingModal/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useParams } from 'react-router-dom';
33
import Button from 'src/components/common/Button';
44
import CopyButton from 'src/components/common/CopyButton';
55
import Modal from 'src/components/common/Modal';
6+
import ERROR_MESSAGE from 'src/constants/error-message';
67
import useWorkspacesContext from 'src/hooks/useWorkspacesContext';
78

89
import style from './style.module.scss';
@@ -19,7 +20,7 @@ function WorkspaceSettingModal({ title, onClose }: WorkspaceSettingModalProps) {
1920
const workspace = workspaces.find((workspace) => workspace.id === Number(id));
2021

2122
if (!workspace) {
22-
throw new Error('일어날 수 없는 일이 일어났어요 ^^');
23+
throw new Error(ERROR_MESSAGE.IMPOSSIBLE_HAPPENED);
2324
}
2425

2526
const { code } = workspace;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const ERROR_MESSAGE = {
2+
OUT_OF_CONTEXT_SCOPE: '해당 Context는 정의된 Scope안에서만 사용 가능해요 ^^',
3+
UNAUTHORIZED: '인증되지 않은 유저에요 ^^',
4+
IMPOSSIBLE_HAPPENED: '일어날 수 없는 일이 발생했어요 ^^',
5+
};
6+
7+
export default ERROR_MESSAGE;

client/src/hooks/useCRDT.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import LinkedList, {
44
RemoteDeleteOperation,
55
} from '@wabinar/crdt/linked-list';
66
import { useRef } from 'react';
7+
import ERROR_MESSAGE from 'src/constants/error-message';
78
import { useUserContext } from 'src/hooks/useUserContext';
89

910
enum OPERATION_TYPE {
@@ -19,7 +20,7 @@ interface RemoteOperation {
1920
export function useCRDT() {
2021
const { user } = useUserContext();
2122

22-
if (!user) throw new Error('인증되지 않은 유저에요 ^^');
23+
if (!user) throw new Error(ERROR_MESSAGE.UNAUTHORIZED);
2324

2425
const { id: clientId } = user;
2526

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useContext } from 'react';
2+
import ERROR_MESSAGE from 'src/constants/error-message';
23
import MeetingContext from 'src/contexts/meeting';
34

45
export function useMeetingContext() {
56
const context = useContext(MeetingContext);
67

7-
if (!context)
8-
throw new Error('ConfContext는 정의된 스코프 안에서만 사용 가능해요 ^^');
8+
if (!context) throw new Error(ERROR_MESSAGE.OUT_OF_CONTEXT_SCOPE);
99

1010
return context;
1111
}

client/src/hooks/useSelectedMom.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useContext } from 'react';
2+
import ERROR_MESSAGE from 'src/constants/error-message';
23
import { SelectedMomContext } from 'src/contexts/selected-mom';
34

45
export default function useSelectedMom() {
56
const context = useContext(SelectedMomContext);
67

7-
if (!context) throw new Error('아니요. 없어요.');
8+
if (!context) throw new Error(ERROR_MESSAGE.OUT_OF_CONTEXT_SCOPE);
89

910
return context;
1011
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useContext } from 'react';
2+
import ERROR_MESSAGE from 'src/constants/error-message';
23
import { SocketContext } from 'src/contexts/socket';
34

45
export default function useSocketContext() {
56
const context = useContext(SocketContext);
67

7-
if (!context)
8-
throw new Error('SocketContext는 정의된 스코프 안에서만 사용 가능해요 ^^');
8+
if (!context) throw new Error(ERROR_MESSAGE.OUT_OF_CONTEXT_SCOPE);
99

1010
return context;
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useContext } from 'react';
2+
import ERROR_MESSAGE from 'src/constants/error-message';
23
import UserContext from 'src/contexts/user';
34

45
export function useUserContext() {
56
const context = useContext(UserContext);
67

7-
if (!context)
8-
throw new Error('UserContext는 정의된 스코프 안에서만 사용 가능해요 ^^');
8+
if (!context) throw new Error(ERROR_MESSAGE.OUT_OF_CONTEXT_SCOPE);
99

1010
return context;
1111
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useContext } from 'react';
2+
import ERROR_MESSAGE from 'src/constants/error-message';
23
import WorkspacesContext from 'src/contexts/workspaces';
34

45
export default function useWorkspacesContext() {
56
const context = useContext(WorkspacesContext);
67

7-
if (!context)
8-
throw new Error('UserContext는 정의된 스코프 안에서만 사용 가능해요 ^^');
8+
if (!context) throw new Error(ERROR_MESSAGE.OUT_OF_CONTEXT_SCOPE);
99

1010
return context;
1111
}

server/apis/auth/service.github.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import env from '@config';
2+
import ERROR_MESSAGE from '@constants/error-message';
23
import AuthorizationError from '@errors/authorization-error';
34
import axios from 'axios';
45

@@ -25,7 +26,7 @@ export const getAccessToken = async (code: string) => {
2526
);
2627

2728
if (accessTokenResponse.error) {
28-
throw new Error('access token 생성 요청 실패');
29+
throw new Error(ERROR_MESSAGE.ACCESS_TOKEN_REQUEST_FAILED);
2930
}
3031

3132
return accessTokenResponse;
@@ -39,7 +40,7 @@ export const getGithubUser = async (accessToken: string, tokenType: string) => {
3940
});
4041

4142
if (user.error) {
42-
throw new AuthorizationError('OAuth 유저 정보 요청 실패');
43+
throw new AuthorizationError(ERROR_MESSAGE.UNAUTHORIZED_OAUTH);
4344
}
4445

4546
return user;

0 commit comments

Comments
 (0)