Skip to content

Conversation

@kongwoojin
Copy link
Member

PR 개요

PR 체크리스트

  • Code convention을 잘 지켰나요?
  • Lint check를 수행하였나요?
  • Assignees를 추가했나요?

작업사항

  • 버그 수정
  • 신규 기능
  • 코드 스타일 수정 (포맷팅 등)
  • 리팩토링 (기능 수정 X, API 수정 X)
  • 기타

작업사항의 상세한 설명

  • HttpException을 매핑하기 위한 mapHttpFailure 함수를 추가했습니다.
  • UserRepository에 적용했습니다.

기존의 HttpException을 매핑하는 로직은 다음과 같았습니다.

runCatching {
    userRemoteDataSource.findLoginIdBySms(SmsVerifyRequest(phone, verificationCode)).loginId
}.onFailure { exception ->
    return Result.failure(
        when (exception) {
            is HttpException -> {
                when (exception.code()) {
                    400 -> KoinUserException.PhoneNumberInvalidException()
                    401 -> KoinUserException.UnauthorizedException()
                    404 -> KoinUserException.PhoneNumberNotFoundException()
                    else -> exception.getErrorResponse().toKoinUnknownErrorException()
                }
            }

            else -> exception
        }
    )
}

onFailure 안에서 HttpException을 필터링하고, 다시 status code에 따라 분기처리를 진행하고, else 처리까지 진행했습니다.

이와 동일한 코드가 반복되었고, 이는 심각한 코드 중복과 유지 보수의 어려움을 유발했습니다.

따라서, HttpException을 매핑하기 위한 mapHttpFailure 함수를 추가하여 이 문제를 해결했습니다.

해당 함수를 적용한 코드는 다음과 같습니다.

runCatching {
    userRemoteDataSource.findLoginIdBySms(SmsVerifyRequest(phone, verificationCode)).loginId
}.mapHttpFailure(
    e400 = KoinUserException.PhoneNumberInvalidException(),
    e401 = KoinUserException.UnauthorizedException(),
    e404 = KoinUserException.PhoneNumberNotFoundException()
)

status code에 맞는 Exception을 parameter로 넘겨주면 mapping이 가능합니다.

선언되지 않은 HttpException일 경우, KoinUnknownErrorException이 반환됩니다.

논의 사항

X

스크린샷

추가내용

  • develop, sprint 브랜치를 향하고 있습니다
  • production 브랜치를 향하고 있습니다

@kongwoojin kongwoojin self-assigned this Jan 29, 2026
@kongwoojin kongwoojin requested a review from a team as a code owner January 29, 2026 18:31
@github-actions github-actions bot added the refactor Code refactoring label Jan 29, 2026
@kongwoojin kongwoojin changed the title Refactor/#1254 refactor http exception mapper [Refactor][Koin Project] HttpException 매핑을 위한 mapHttpFailure 함수 추가 Jan 29, 2026
@github-actions github-actions bot requested review from JaeYoung290 and KYM-P January 29, 2026 18:32
Copy link
Collaborator

@KYM-P KYM-P left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOOD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

koin project refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants