From 539ed46915bd256f62ff5e2187070fb0bb24f663 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Sat, 14 Oct 2023 15:29:16 +0900 Subject: [PATCH] refactor : Define a constant instead of duplicating this literal #PAR-383 --- .../core/data/repository/ResultRepositoryImpl.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt index 43dd4d4d..635e842d 100644 --- a/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt +++ b/core/data/src/main/java/online/partyrun/partyrunapplication/core/data/repository/ResultRepositoryImpl.kt @@ -31,6 +31,9 @@ class ResultRepositoryImpl @Inject constructor( private val battlePreferencesDataSource: BattlePreferencesDataSource, private val singlePreferencesDataSource: SinglePreferencesDataSource ) : ResultRepository { + companion object { + const val UNKNOWN_ERROR = "Unknown Error" + } override suspend fun getBattleResults(): Flow> { return apiRequestFlow { @@ -59,7 +62,7 @@ class ResultRepositoryImpl @Inject constructor( singleRunningHistoryDao.insertAllSingleRunningHistory(result.toEntity()) emit(Result.Success(Unit)) }.onException { e -> - emit(Result.Failure(e.message ?: "UnKnown Error", -1)) + emit(Result.Failure(e.message ?: UNKNOWN_ERROR, -1)) } } @@ -70,7 +73,7 @@ class ResultRepositoryImpl @Inject constructor( battleRunningHistoryDao.insertAllBattleRunningHistory(result.toEntity()) emit(Result.Success(Unit)) }.onException { e -> - emit(Result.Failure(e.message ?: "UnKnown Error", -1)) + emit(Result.Failure(e.message ?: UNKNOWN_ERROR, -1)) } } @@ -80,7 +83,7 @@ class ResultRepositoryImpl @Inject constructor( try { Result.Success(SingleRunningHistory(entityList.map { it.toDomainModel() })) } catch (e: Exception) { - Result.Failure(e.message ?: "Unknown Error", -1) + Result.Failure(e.message ?: UNKNOWN_ERROR, -1) } } } @@ -91,7 +94,7 @@ class ResultRepositoryImpl @Inject constructor( try { Result.Success(BattleRunningHistory(entityList.map { it.toDomainModel() })) } catch (e: Exception) { - Result.Failure(e.message ?: "Unknown Error", -1) + Result.Failure(e.message ?: UNKNOWN_ERROR, -1) } } } @@ -103,7 +106,7 @@ class ResultRepositoryImpl @Inject constructor( battleRunningHistoryDao.deleteAllBattleRunningHistories() emit(Result.Success(Unit)) } catch (e: Exception) { - emit(Result.Failure(e.message ?: "Unknown Error", -1)) + emit(Result.Failure(e.message ?: UNKNOWN_ERROR, -1)) } }