Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
guizmaii committed Aug 14, 2024
1 parent 65641d7 commit 8127c2c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions zio-http/shared/src/main/scala/zio/http/URL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -280,21 +280,23 @@ final case class URL(
}

object URL {
def empty: URL = URL(Path.empty)
val empty: URL = URL(path = Path.empty)

/**
* Proper implementation of [[java.net.MalformedURLException]] which, unlike
* the Java version, can propagate the cause.
*/
final case class MalformedURLException(message: String, cause: Option[Throwable])
extends IOException(message, cause.orNull)
final case class MalformedURLException(rawUrl: String, cause: Option[Throwable])
extends IOException(cause.orNull) {
override def getMessage: String = s"""Invalid URL: "$rawUrl""""
}

def decode(string: String): Either[MalformedURLException, URL] = {
def decode(rawUrl: String): Either[MalformedURLException, URL] = {
def invalidURL(e: Option[Throwable]): Either[MalformedURLException, URL] =
Left(MalformedURLException(message = s"""Invalid URL: "$string"""", cause = e))
Left(MalformedURLException(rawUrl = rawUrl, cause = e))

try {
val uri = new URI(string)
val uri = new URI(rawUrl)
val url = if (uri.isAbsolute) fromAbsoluteURI(uri) else fromRelativeURI(uri)

url match {
Expand Down

0 comments on commit 8127c2c

Please sign in to comment.