Skip to content

Commit

Permalink
Handle invalid hostAddresses gracefully when a service is found
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrisimx committed Jan 9, 2025
1 parent a9f46dc commit 46d5847
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,22 @@ class ScannerDiscovery(
val urls = mutableListOf<String>()

for (address in p0.hostAddresses) {
val url = HttpUrl.Builder()
.host(address.hostAddress!!)
.addPathSegment(rs)
.scheme("http")
.build()
Log.d(TAG, "Built URL: $url")
val sanitizedURL = address.hostAddress!!.substringBefore('%')
val url = try {
HttpUrl.Builder()
.host(sanitizedURL)
.addPathSegment(rs)
.scheme("http")
.build()
} catch (e: Exception) {
Log.e(
TAG,
"Couldn't built address from: ${address.hostAddress} Exception: $e"
)
continue
}

Log.d(TAG, "Built URL: $url with address: ${address.hostAddress}")
urls.add(url.toString())
}

Expand Down

0 comments on commit 46d5847

Please sign in to comment.