Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UserRepositoryImpl @Inject constructor(
Result.success(Unit)
} else {
Result.failure(
Exception("올바르지 않은 닉네임이에요.")
Exception("이미 사용 중인 닉네임이에요.")
)
Comment on lines 35 to 37
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

사용자에게 보여주는 오류 메시지를 Exception에 문자열로 하드코딩하는 방식은 몇 가지 단점이 있습니다.

  1. 유지보수: 문자열이 코드 전체에 흩어져 있으면 관리하기 어렵습니다.
  2. 재사용성: 동일한 오류에 대해 다른 메시지를 사용하게 될 수 있습니다.
  3. 다국어 지원: 향후 다국어 지원 시 번역이 힘들어집니다.

Result.failureException 대신 오류 유형을 나타내는 sealed classenum을 전달하는 것을 고려해보세요. 예를 들어, 다음과 같이 정의할 수 있습니다.

sealed class NicknameCheckError : Throwable() {
    data object Duplicate : NicknameCheckError()
    data class ApiError(val msg: String?) : NicknameCheckError()
    data object NetworkError : NicknameCheckError()
}

이렇게 하면 Repository는 오류의 '종류'만 전달하고, ViewModel이나 UI 계층에서 이 오류 종류에 따라 적절한 문자열 리소스(R.string.*)를 사용자에게 보여줄 수 있습니다. 이는 역할 분리를 명확히 하고 코드의 테스트 용이성과 유지보수성을 높여줍니다. 이 PR의 범위를 넘어서는 개선일 수 있지만, 장기적인 관점에서 적용을 고려해보시면 좋을 것 같습니다.

Copy link
Member

Choose a reason for hiding this comment

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

제가 잘 몰라서 그런데 올바르지 않은 닉네임이랑 이미 사용 중인 닉네임인 경우 각각 오류 처리 흐름이 어떻게 되나요???

이미 사용 중인 경우는 ApiResult.Success이지만 result.data가 없는 건가요??

Copy link
Member Author

Choose a reason for hiding this comment

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

중복인 경우: ApiResult.Success, result.data = false
규칙에 어긋난 경우: ApiResult.Failure, result.message가 무슨 규칙에 어떻게 어긋났는지 메세지

입니다!
이름 변경 로직 개발할 때 저도 이 부분 로직을 정확히 이해 못했어서 그냥 올바르지 않은 닉네임으로 퉁쳤던거같아요....

}
}
Expand Down