You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectionError.kt 986B

123456789101112131415161718192021222324252627
  1. package com.dmdirc.ktirc.model
  2. import java.net.ConnectException
  3. import java.nio.channels.UnresolvedAddressException
  4. import java.security.cert.CertificateException
  5. /**
  6. * Possible types of errors that occur whilst connecting.
  7. */
  8. enum class ConnectionError {
  9. /** An error occurred, but we don't really know what. */
  10. Unknown,
  11. /** The hostname did not resolve to an IP address. */
  12. UnresolvableAddress,
  13. /** A connection couldn't be established to the given host/port. */
  14. ConnectionRefused,
  15. /** There was an issue with the TLS certificate the server presented. */
  16. BadTlsCertificate,
  17. }
  18. internal fun Exception.toConnectionError() =
  19. when (this) {
  20. is UnresolvedAddressException -> ConnectionError.UnresolvableAddress
  21. is CertificateException -> ConnectionError.BadTlsCertificate
  22. is ConnectException -> ConnectionError.ConnectionRefused
  23. else -> ConnectionError.Unknown
  24. }