Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -1,7 +1,52 @@
package team.retum.jobisandroidv2

import android.app.Application
import android.content.Intent
import android.widget.Toast
import com.google.firebase.Firebase
import com.google.firebase.crashlytics.crashlytics
import dagger.hilt.android.HiltAndroidApp
import team.retum.common.exception.ConnectionTimeOutException
import team.retum.common.exception.OfflineException
import team.retum.common.exception.ReissueException
import team.retum.common.exception.UnknownException
import kotlin.system.exitProcess

private const val InternetErrorMsg = "인터넷 연결을 ν™•μΈν•΄μ£Όμ„Έμš”."
private const val TimeoutErrorMsg = "μš”μ²­ μ‹œκ°„μ΄ μ΄ˆκ³Όλ˜μ—ˆμŠ΅λ‹ˆλ‹€.\nλ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”."
private const val LoginErrorMsg = "μœ μ €μ •λ³΄κ°€ ν™•μΈλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.\nλ‹€μ‹œ 둜그인 ν•΄μ£Όμ„Έμš”."
private const val UnknownErrorMsg = "처리 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€."
Comment on lines +15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

λ¬Έμžμ—΄ λ¦¬μ†ŒμŠ€ 관리 κ°œμ„ μ΄ ν•„μš”ν•©λ‹ˆλ‹€.

ν•˜λ“œμ½”λ”©λœ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό res/values/strings.xml둜 μ΄λ™ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. μ΄λ ‡κ²Œ ν•˜λ©΄:

  • λ‹€κ΅­μ–΄ 지원이 μš©μ΄ν•΄μ§‘λ‹ˆλ‹€
  • λ¬Έμžμ—΄ μž¬μ‚¬μš©μ΄ κ°€λŠ₯ν•΄μ§‘λ‹ˆλ‹€
  • μΌκ΄€λœ λ©”μ‹œμ§€ 관리가 κ°€λŠ₯ν•΄μ§‘λ‹ˆλ‹€

λ‹€μŒκ³Ό 같이 λ³€κ²½ν•˜λŠ” 것을 μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

-private const val InternetErrorMsg = "인터넷 연결을 ν™•μΈν•΄μ£Όμ„Έμš”."
-private const val TimeoutErrorMsg = "μš”μ²­ μ‹œκ°„μ΄ μ΄ˆκ³Όλ˜μ—ˆμŠ΅λ‹ˆλ‹€.\nλ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”."
-private const val LoginErrorMsg = "μœ μ €μ •λ³΄κ°€ ν™•μΈλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.\nλ‹€μ‹œ 둜그인 ν•΄μ£Όμ„Έμš”."
-private const val UnknownErrorMsg = "처리 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€."

strings.xml에 μΆ”κ°€:

<resources>
    <string name="error_internet">인터넷 연결을 ν™•μΈν•΄μ£Όμ„Έμš”.</string>
    <string name="error_timeout">μš”μ²­ μ‹œκ°„μ΄ μ΄ˆκ³Όλ˜μ—ˆμŠ΅λ‹ˆλ‹€.\nλ‹€μ‹œ μ‹œλ„ν•΄μ£Όμ„Έμš”.</string>
    <string name="error_login">μœ μ €μ •λ³΄κ°€ ν™•μΈλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.\nλ‹€μ‹œ 둜그인 ν•΄μ£Όμ„Έμš”.</string>
    <string name="error_unknown">처리 쀑 λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.</string>
</resources>


@HiltAndroidApp
class JobisApplication : Application()
class JobisApplication : Application() {
override fun onCreate() {
super.onCreate()

Thread.setDefaultUncaughtExceptionHandler { _, e ->
Firebase.crashlytics.recordException(e)

when (e) {
is OfflineException -> makeToast(InternetErrorMsg)
is ConnectionTimeOutException -> makeToast(TimeoutErrorMsg)
is ReissueException -> makeToast(LoginErrorMsg)
is UnknownException -> makeToast(UnknownErrorMsg)
else -> makeToast(UnknownErrorMsg)
}

val intent = this.packageManager.getLaunchIntentForPackage(this.packageName)
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
this.startActivity(intent)
exitProcess(0)
}
}
}

private fun makeToast(message: String) {
Toast.makeText(
this,
message,
Toast.LENGTH_SHORT,
).show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ data object TooManyRequestException : RuntimeException()
data object ServerException : RuntimeException()
data object OfflineException : RuntimeException()
data object ConnectionTimeOutException : RuntimeException()
data object UnknownException : RuntimeException()
data object ReissueException : RuntimeException()
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import team.retum.common.enums.PlatformType
import team.retum.common.exception.ReissueException
import team.retum.network.BuildConfig
import team.retum.network.api.AuthApi
import team.retum.network.model.response.TokenResponse
Expand Down Expand Up @@ -40,7 +41,7 @@ object RefreshTokenService {
}.onSuccess { token ->
return token
}.onFailure {
throw IllegalStateException("Fail refresh: ${it.message}")
throw ReissueException
Copy link
Contributor

Choose a reason for hiding this comment

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

πŸ› οΈ Refactor suggestion

μ˜ˆμ™Έ 처리λ₯Ό κ°œμ„ ν•΄ μ£Όμ„Έμš”.

ν˜„μž¬ κ΅¬ν˜„μ€ μ›λž˜ λ°œμƒν•œ μ˜ˆμ™Έμ˜ 정보λ₯Ό λͺ¨λ‘ μžƒμ–΄λ²„λ¦½λ‹ˆλ‹€. 디버깅과 문제 해결을 μœ„ν•΄ λ‹€μŒκ³Ό 같은 κ°œμ„ μ„ μ œμ•ˆν•©λ‹ˆλ‹€:

  1. 원인이 λ˜λŠ” μ˜ˆμ™Έλ₯Ό 보쑴
  2. 의미 μžˆλŠ” 였λ₯˜ λ©”μ‹œμ§€ μΆ”κ°€
  3. λ‘œκΉ… μΆ”κ°€

λ‹€μŒκ³Ό 같이 μˆ˜μ •ν•˜λŠ” 것을 μΆ”μ²œλ“œλ¦½λ‹ˆλ‹€:

-            throw ReissueException
+            throw ReissueException("토큰 κ°±μ‹  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€", it)

λ˜ν•œ λ‘œκΉ… κ΅¬ν˜„μ„ μœ„ν•΄ Timberλ‚˜ λ‹€λ₯Έ λ‘œκΉ… 라이브러리λ₯Ό μ‚¬μš©ν•˜λŠ” 것을 κ³ λ €ν•΄λ³΄μ„Έμš”.

Committable suggestion skipped: line range outside the PR's diff.

}.getOrThrow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import team.retum.common.exception.OfflineException
import team.retum.common.exception.ServerException
import team.retum.common.exception.TooManyRequestException
import team.retum.common.exception.UnAuthorizedException
import team.retum.common.exception.UnknownException
import java.net.SocketTimeoutException
import java.net.UnknownHostException

Expand Down Expand Up @@ -63,6 +64,6 @@ class RequestHandler<T> {
} catch (e: UnknownHostException) {
throw OfflineException
} catch (e: Throwable) {
throw e
throw UnknownException
}
}
Loading