Skip to content

Commit

Permalink
refactor : Define a constant instead of duplicating this literal #PAR…
Browse files Browse the repository at this point in the history
…-383
  • Loading branch information
nohjunh committed Oct 14, 2023
1 parent 5219261 commit 539ed46
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<BattleResult>> {
return apiRequestFlow {
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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))
}
}

Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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))
}
}

Expand Down

0 comments on commit 539ed46

Please sign in to comment.