Skip to content

Commit 99f2f0a

Browse files
frcrothfm3
andauthored
Handle http unknown host exception (#7422)
* Handle http unknown host exception * Update changelog * change wording in comment --------- Co-authored-by: Florian M <[email protected]>
1 parent f484cb7 commit 99f2f0a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CHANGELOG.unreleased.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
1919
- Searching the segments in the sidebar will highlight newly focused segments properly now. [#7406](https://github.com/scalableminds/webknossos/pull/7406)
2020
- Fixed a bug when opening a task for which a mag restriction exists. The bug only occurred when the referenced mag didn't exist in the dataset. [#7403](https://github.com/scalableminds/webknossos/pull/7403)
2121
- Fixed styling issues with the maintenance banner so that it no longer overlaps other menus, tabs, and buttons. [#7421](https://github.com/scalableminds/webknossos/pull/7421)
22+
- Exploring HTTP uris of unknown hosts no longer causes an exception error message to be displayed. [#7422](https://github.com/scalableminds/webknossos/pull/7422)
2223

2324
### Removed
2425

util/src/main/scala/com/scalableminds/util/tools/Fox.scala

+12
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ object Fox extends FoxImplicits {
242242

243243
failure.msg + formatStackTrace(failure) + formatChain(failure.chain)
244244
}
245+
246+
/**
247+
* Transform a Future[T] into a Fox[T] such that if the Future contains an exception, it is turned into a Fox.failure
248+
*/
249+
def transformFuture[T](future: Future[T])(implicit ec: ExecutionContext): Fox[T] =
250+
for {
251+
fut <- future.transform {
252+
case Success(value) => Try(Fox.successful(value))
253+
case scala.util.Failure(e) => Try(Fox.failure(e.getMessage, Full(e)))
254+
}
255+
f <- fut
256+
} yield f
245257
}
246258

247259
class Fox[+A](val futureBox: Future[Box[A]])(implicit ec: ExecutionContext) {

webknossos-datastore/app/com/scalableminds/webknossos/datastore/datavault/HttpsDataVault.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class HttpsDataVault(credential: Option[DataVaultCredential], ws: WSClient) exte
5050
headerInfoCache.getOrLoad(
5151
uri, { uri =>
5252
for {
53-
response <- ws.url(uri.toString).withRequestTimeout(readTimeout).head()
53+
response <- Fox.transformFuture(ws.url(uri.toString).withRequestTimeout(readTimeout).head())
5454
acceptsPartialRequests = response.headerValues("Accept-Ranges").contains("bytes")
5555
dataSize = response.header("Content-Length").map(_.toLong).getOrElse(0L)
5656
} yield (acceptsPartialRequests, dataSize)
@@ -60,19 +60,20 @@ class HttpsDataVault(credential: Option[DataVaultCredential], ws: WSClient) exte
6060
private def getWithRange(uri: URI, range: NumericRange[Long])(implicit ec: ExecutionContext): Fox[WSResponse] =
6161
for {
6262
_ <- ensureRangeRequestsSupported(uri)
63-
response <- buildRequest(uri).withHttpHeaders("Range" -> s"bytes=${range.start}-${range.end - 1}").get()
63+
response <- Fox.transformFuture(
64+
buildRequest(uri).withHttpHeaders("Range" -> s"bytes=${range.start}-${range.end - 1}").get())
6465
_ = updateRangeRequestsSupportedForResponse(response)
6566
} yield response
6667

6768
private def getWithSuffixRange(uri: URI, length: Long)(implicit ec: ExecutionContext): Fox[WSResponse] =
6869
for {
6970
_ <- ensureRangeRequestsSupported(uri)
70-
response <- buildRequest(uri).withHttpHeaders("Range" -> s"bytes=-$length").get()
71+
response <- Fox.transformFuture(buildRequest(uri).withHttpHeaders("Range" -> s"bytes=-$length").get())
7172
_ = updateRangeRequestsSupportedForResponse(response)
7273
} yield response
7374

7475
private def getComplete(uri: URI)(implicit ec: ExecutionContext): Fox[WSResponse] =
75-
buildRequest(uri).get()
76+
Fox.transformFuture(buildRequest(uri).get())
7677

7778
private def ensureRangeRequestsSupported(uri: URI)(implicit ec: ExecutionContext): Fox[Unit] =
7879
for {

0 commit comments

Comments
 (0)