Skip to content

Commit

Permalink
Handle public id address failure gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel committed Dec 11, 2023
1 parent ffcebd8 commit 438339c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ object Presence extends ZonedDateTimeCodecs {
// when one client has reported going offline, there still may be other clients running
val state = if (age < 70 && d.state == "offline") "online" else d.state
//println(s"Report $login as $d")
login -> LocationInfo(Locations.locationFromIpAddress(d.ipAddress), lastSeen, state, Relation.Allowed, watchedBy)
val location = if (d.ipAddress.nonEmpty) Locations.locationFromIpAddress(d.ipAddress) else ""
login -> LocationInfo(location, lastSeen, state, Relation.Allowed, watchedBy)
}.getOrElse(login -> LocationInfo("", now, "unknown", Relation.Allowed, watchedBy))
}
if (requests) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ class UserRestAPIServer(val userAuth: Main.GitHubAuthResult) extends UserRestAPI
}

checkState(state)
checkIpAddress(ipAddress)
// if user did not provide its IP address, check how we see it from out side
val publicIPAddress = if (ipAddress.nonEmpty) {
checkIpAddress(ipAddress)
} else {

}
// when the user is away or invisible, do not update his presence
if (state != "away" && state != "invisible") {
//println(s"Presence.reportUser ${userAuth.login} $state")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class PagePresenter(
def startListening(ipAddress: String): Unit = {
val token = ApplicationContext.currentToken
assert(token.nonEmpty)
assert(ipAddress.nonEmpty)

lastActive = System.currentTimeMillis()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ object PublicIpAddress {
println(s"Obtained a public IP address ${string.trim}")
promise.success(string.trim)
case Left(value) =>
promise.failure(new UnsupportedOperationException(value))
println(s"Unable to obtain a public IP address: error ${r.code}")
promise.success("")
}
case Failure(ex) =>
promise.failure(ex)
// when failed, provide some dummy fallback
println(s"Unable to obtain a public IP address, $ex")
promise.success("")
}
promise.future
}
Expand Down

0 comments on commit 438339c

Please sign in to comment.