Skip to content

Commit

Permalink
add connection failed parse
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Sep 23, 2024
1 parent 20e7b47 commit c5f3715
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions common/src/main/java/com/pedro/common/ConnectionFailed.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* * Copyright (C) 2024 pedroSG94.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package com.pedro.common

/**
* Created by pedro on 23/9/24.
*/
enum class ConnectionFailed {
ENDPOINT_MALFORMED, REFUSED, CLOSED_BY_SERVER, NO_INTERNET, UNKNOWN;

companion object {
fun parse(reason: String): ConnectionFailed {
return if (
reason.contains("network is unreachable", ignoreCase = true) ||
reason.contains("software caused connection abort", ignoreCase = true) ||
reason.contains("no route to host", ignoreCase = true)
) {
NO_INTERNET
} else if (reason.contains("broken pipe", ignoreCase = true)) {
CLOSED_BY_SERVER
} else if (reason.contains("connection refused", ignoreCase = true)) {
REFUSED
} else if (reason.contains("endpoint malformed", ignoreCase = true)) {
ENDPOINT_MALFORMED
} else {
UNKNOWN
}
}
}
}

0 comments on commit c5f3715

Please sign in to comment.