Skip to content

Commit d920968

Browse files
committed
refactor: ENV 오류 전용 공통 오류 객체 추가
1 parent 939b173 commit d920968

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

src/apis/instance.request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import returnFetch, { FetchArgs } from 'return-fetch';
22

33
import { captureException, setContext } from '@sentry/nextjs';
4-
import { ServerNotRespondingError } from '@/errors';
4+
import { EnvNotFoundError, ServerNotRespondingError } from '@/errors';
55

66
const BASE_URL = process.env.NEXT_PUBLIC_BASE_URL;
77
const ABORT_MS = Number(process.env.NEXT_PUBLIC_ABORT_MS);
88

99
if (Number.isNaN(ABORT_MS)) {
10-
throw new Error('ABORT_MS가 ENV에서 설정되지 않았습니다');
10+
throw new EnvNotFoundError('ABORT_MS');
1111
}
1212

1313
if (!BASE_URL) {
14-
throw new Error('BASE_URL이 ENV에서 설정되지 않았습니다.');
14+
throw new EnvNotFoundError('BASE_URL');
1515
}
1616

1717
type ErrorType = {

src/components/auth-required/main/Section/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
'use client';
22

3-
import { useState } from 'react';
43
import { useQueryClient } from '@tanstack/react-query';
4+
import { useState } from 'react';
5+
import { EnvNotFoundError, UserNameNotFoundError } from '@/errors';
6+
import { trackUserEvent, MessageEnum } from '@/utils/trackUtil';
57
import { parseNumber } from '@/utils/numberUtil';
68
import { COLORS, PATHS } from '@/constants';
7-
import { Icon } from '@/components';
89
import { PostType, UserDto } from '@/types';
9-
import { trackUserEvent, MessageEnum } from '@/utils/trackUtil';
10-
import { UserNameNotFound } from '@/errors';
10+
import { Icon } from '@/components';
1111
import { Graph } from './Graph';
1212

1313
export const Section = (p: PostType) => {
1414
const [open, setOpen] = useState(false);
1515
const client = useQueryClient();
1616

1717
const { username } = client.getQueryData([PATHS.ME]) as UserDto;
18+
const { NEXT_PUBLIC_VELOG_URL } = process.env;
19+
1820
if (!username) {
19-
throw new UserNameNotFound();
21+
throw new UserNameNotFoundError();
2022
}
23+
if (NEXT_PUBLIC_VELOG_URL) {
24+
throw new EnvNotFoundError('NEXT_PUBLIC_VELOG_URL');
25+
}
26+
2127
const url = `${process.env.NEXT_PUBLIC_VELOG_URL}/@${username}/${p.slug}`;
2228

2329
return (
File renamed without changes.

src/errors/fetch.error.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ export class NotFoundError extends CustomError {
1717
super(message, code, 400);
1818
}
1919
}
20+
21+
export class EnvNotFoundError extends CustomError {
22+
constructor(message: string) {
23+
super(
24+
`${message}이(가) ENV에서 설정되지 않았습니다`,
25+
'EnvNotFoundError',
26+
0,
27+
);
28+
}
29+
}

src/errors/main.error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CustomError } from './instance.error';
22

3-
export class UserNameNotFound extends CustomError {
3+
export class UserNameNotFoundError extends CustomError {
44
constructor() {
55
super('username not found', 'UserNameNotFound');
66
}

0 commit comments

Comments
 (0)