병렬 API 호출에서 디버깅과 성능을 모두 잡는 방법: Promise.allSettled 적용 #115
sgoldenbird
started this conversation in
Trouble Shooting
Replies: 0 comments
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.
-
🐞 문제 상황 (Problem Description)
두 개의 비동기 API (
getDashboardDetail,getMemberList)를 병렬로 호출하기 위해Promise.all()을 사용했지만,하나라도 실패하면 전체가 reject되고, 가장 먼저 실패한 에러 하나만 전달되어 어떤 API가 실패했는지 정확히 확인하기 어려웠다.
💻 환경 정보 (Environment)
🔍 발생 원인 분석 (Investigation)
Promise.all()은 첫 번째 reject된 Promise의 에러만 반환함try...catch에서 받은 error가getDashboardDetail의 것인지,getMemberList의 것인지 구분 불가🛠 시도해본 해결 방법 (Attempts)
방법 1:
await로 순차 실행방법 2:
Promise.allSettled()사용 (채택)장점:
⚠ 단점: 처리 코드가 다소 복잡해짐
✅ 최종 해결 방법 (Final Solution)
Promise.allSettled()을 사용하여 모든 API 요청을 병렬로 수행
💡 알게 된 점 (Lessons Learned)
Promise.all()은 간단하지만 에러 디버깅에는 불리한 구조Promise.allSettled()은 성능(병렬성)과 에러 가시성을 모두 확보할 수 있는 더 나은 대안Beta Was this translation helpful? Give feedback.
All reactions