api 로직 정리
#199
Replies: 2 comments 6 replies
-
따로따로 후처리 하지않고도, 깔끔하게 처리될수 있는 방식이라 좋은것 같습니다! 그런데 이 방식을 사용한다면 |
Beta Was this translation helpful? Give feedback.
2 replies
-
axios interceptors 내부 미들웨어? 함수의 경우 화살표 함수로가 아닌 함수 선언으로 해야되는건가요? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@sumi-0011 @coolsmart2
api 요청 쪽을 정리해봤어요. 이렇게 스타일을 통일하면 어떨까 하는데, 의견 남겨주세요!
데이터 흐름 순으로 작성해봤습니다.
apis > index.ts
인터셉터에서 아래와 같이 에러를 일괄적으로 처리합니다.
전체 코드는 아래처럼 변경될 것 같아요.
types > apiResponse.ts
api 응답을 위한 interface를 설계해 놓았습니다.
apis > someFile
인터셉터에서 에러 처리를 하고 있으므로, 여기서는 error를 throw 해주기만 하면 됩니다.
components > someComponent.tsx
constants > responseCode.ts
서버에서 뿌려주는 에러 코드들은 아래와 같이 상수로 사용합니다.
이렇게 일괄적으로 api를 사용하는게 어떤가 싶어요.
기존에 윤우님이 instanceof로 사용하는 것들은 서버에서
code
와description
을 주는데도 프론트에서 한번 더 내려서 쓰는 느낌이라 코드도 길어지고 분기도 너무 많이 되는 것 같아요.예를 들면, 아래와 같이 코드 양이 줄고 일괄적으로 처리할 수 있을 것 같아요. 의견 남겨주세요 🙂

Beta Was this translation helpful? Give feedback.
All reactions