Skip to content

Commit 5a40983

Browse files
authored
Merge branch 'develop' into 1-feature/global-modal-management
2 parents 958636d + a969ef5 commit 5a40983

File tree

22 files changed

+1303
-39
lines changed

22 files changed

+1303
-39
lines changed

.vscode/typescript.code-snippets

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"import { styled } from 'styled-components'",
77
"",
88
"export const ${1:${TM_DIRECTORY/^.+\\\\(.*)$/$1/}} = styled.div`",
9-
" $2",
9+
" ${2}",
1010
"`;",
1111
],
1212
},
@@ -16,9 +16,55 @@
1616
"body": [
1717
"import { styled } from 'styled-components'",
1818
"",
19-
"export const ${3:${TM_DIRECTORY/.*\\/(.*)$/$1/}} = styled.div`",
20-
" $2",
19+
"export const ${1:${TM_DIRECTORY/.*\\/(.*)$/$1/}} = styled.div`",
20+
" ${2}",
2121
"`;",
2222
],
2323
},
24+
"Axios Request Function": {
25+
"prefix": "api-req",
26+
"body": [
27+
"import { AxiosError } from 'axios';",
28+
"import { APIResponse, ErrorResponse } from '~types/apiResponse';",
29+
"import { axiosInstance } from '~apis/axiosInstance';",
30+
"",
31+
"interface ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}Request {",
32+
" ${2}",
33+
"}",
34+
"",
35+
"interface ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}Response {",
36+
" ${3}",
37+
"}",
38+
"",
39+
"export const ${4:${TM_FILENAME_BASE/(.*)/${1:/camelcase}/}} = async (req: ${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}Request): Promise<APIResponse<${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}Response>> => {",
40+
" try {",
41+
" const { data } = await axiosInstance.${5|get,post,put,patch,delete|}<APIResponse<${1:${TM_FILENAME_BASE/(.*)/${1:/pascalcase}/}}Response>>(",
42+
" `/${6:endpoint}`,",
43+
" req",
44+
" );",
45+
" return data;",
46+
" } catch (error) {",
47+
" if (error instanceof AxiosError) {",
48+
" const { response, request } = error as AxiosError<ErrorResponse>;",
49+
"",
50+
" if (response) {",
51+
" //? 서버에서 응답이 왔지만 에러가 발생한 경우",
52+
" console.error('${7:ErrorMessage}', response.data);",
53+
" throw new Error(response.data.message ?? '요청 실패');",
54+
" }",
55+
"",
56+
" if (request) {",
57+
" //? 요청 자체가 실패한 경우 : 네트워크 연결 문제나 CORS 에러와 같은 클라이언트 측 문제",
58+
" console.error('요청 에러:', request);",
59+
" throw new Error('네트워크 연결을 확인해주세요');",
60+
" }",
61+
" }",
62+
"",
63+
" console.error('예상치 못한 에러:', error);",
64+
" throw new Error('다시 시도해주세요');",
65+
" }",
66+
"};",
67+
],
68+
"description": "Axios request function template with error handling",
69+
},
2470
}

0 commit comments

Comments
 (0)