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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.9.10'
id 'org.jetbrains.kotlin.jvm' version '1.9.23'
}

test {
Expand Down
12 changes: 11 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 @@ -60,5 +64,11 @@ fun main() {

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

val dmp = logger.dump()
println("Список ошибок:")
dmp.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>()
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<R>(val error: R): NetworkResponse<Nothing, R>()

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