diff --git a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala index 9e7cbf5c..e4359d23 100644 --- a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala +++ b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala @@ -44,13 +44,13 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv) extends Specifica "url" should { "throw an exception on invalid url" in { withClient() { client => - { client.url("localhost") } must throwA[Throwable] + { client.url("localhost") } must throwAn[IllegalArgumentException] } } "not throw exception on valid url" in { withClient() { client => - { client.url(s"http://localhost:$testServerPort") } must not(throwA[Throwable]) + { client.url(s"http://localhost:$testServerPort") } must not(throwAn[IllegalArgumentException]) } } } diff --git a/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSClient.scala b/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSClient.scala index 546e6add..741861b3 100644 --- a/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSClient.scala +++ b/play-ahc-ws-standalone/src/main/scala/play/api/libs/ws/ahc/StandaloneAhcWSClient.scala @@ -18,7 +18,6 @@ import play.shaded.ahc.org.asynchttpclient.{ Response => AHCResponse, _ } import scala.collection.immutable.TreeMap import scala.compat.java8.FunctionConverters import scala.concurrent.{ Await, Future, Promise } -import scala.util.{ Failure, Success, Try } /** * A WS client backed by an AsyncHttpClient. @@ -78,10 +77,14 @@ class StandaloneAhcWSClient @Inject() (asyncHttpClient: AsyncHttpClient)(implici private def validate(url: String): Unit = { // Recover from https://github.com/AsyncHttpClient/async-http-client/issues/1149 - Try(Uri.create(url)).transform(Success(_), { + try { + Uri.create(url) + } catch { + case iae: IllegalArgumentException => + throw new IllegalArgumentException(s"Invalid URL $url", iae) case npe: NullPointerException => - Failure(new IllegalArgumentException(s"Invalid URL $url", npe)) - }).get + throw new IllegalArgumentException(s"Invalid URL $url", npe) + } } private[ahc] def executeStream(request: Request): Future[StreamedResponse] = {