Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/main/kotlin/ru/kotlin/homework/network/NetworkLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class ErrorLogger<E : Throwable> {
println("Error at $date: ${error.message}")
}
}

fun dump(): List<Pair<LocalDateTime, E>> {
return errors
}
}

fun processThrowables(logger: ErrorLogger<Throwable>) {
Expand All @@ -42,7 +46,7 @@ fun processThrowables(logger: ErrorLogger<Throwable>) {
logger.dumpLog()
}

fun processApiErrors(apiExceptionLogger: ErrorLogger<ApiException>) {
fun processApiErrors(apiExceptionLogger: ErrorLogger<in ApiException>) {
apiExceptionLogger.log(Success("Success"))
Thread.sleep(100)
apiExceptionLogger.log(Success(Circle))
Expand All @@ -52,6 +56,7 @@ fun processApiErrors(apiExceptionLogger: ErrorLogger<ApiException>) {
apiExceptionLogger.dumpLog()
}


fun main() {
val logger = ErrorLogger<Throwable>()

Expand All @@ -60,5 +65,11 @@ fun main() {

println("Processing Api:")
processApiErrors(logger)

val errorList = logger.dump()
println("List of errors:")
errorList.forEach { (date, error) ->
println("Error at $date: ${error.message}")
}
}

6 changes: 3 additions & 3 deletions src/main/kotlin/ru/kotlin/homework/network/NetworkResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import java.time.LocalDateTime
/**
* Network result
*/
sealed class NetworkResponse<T, R> {
sealed class NetworkResponse<out T, out R> {
val responseDateTime: LocalDateTime = LocalDateTime.now()
}

/**
* Network success
*/
data class Success<T, R>(val resp: T): NetworkResponse<T, R>()
data class Success<out T>(val resp: T): NetworkResponse<T, Nothing>()

/**
* Network error
*/
data class Failure<T, R>(val error: R): NetworkResponse<T, R>()
data class Failure<out R>(val error: R): NetworkResponse<Nothing, R>()

val s1 = Success("Message")
val r11: NetworkResponse<String, Error> = s1
Expand Down