You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Requires "com.softwaremill.sttp.client3" %% "zio" % "3.8.15" Scastie link to the same code.
importzio._importsttp.client3._importsttp.client3.httpclient.zio.HttpClientZioBackendobjectMainextendsZIOAppDefault {
valprogram=for {
backend <-HttpClientZioBackend.scoped()
response <- basicRequest.get(uri"https://example.com")
// the problem is here
.header("X-Api-Key", "Я ЛЮБЛЮ БОРЩ")
.response(asString)
.send(backend)
} yield ()
valrun= program
.catchAllDefect { defect =>// It should have been an error?ZIO.consoleWith(_.printLine(s"Captured defect=$defect"))
}
}
While non-latin header values are forbidden, it's confusing that such an error is a ZIO defect.
What is more confusing is that sttp doesn't provide a proper way to validate the header value.
Therefore, there is no way to overcome this error easily.
I'd expect there is a way to either validate the header or handle such errors as ZIO's errors, because the header value may be a user input (therefore, it may be incorrect).
Is there any reason why this invalid header value isn't handled as "normal" error, but as a defect?
The text was updated successfully, but these errors were encountered:
sttp model contains methods for creating the model classes w/ validation (as described here), however for some reason the header value is not validated (while it should, along the rules specified here). So we should fix this, so that .header(Header.unsafeApply("X-Api-Key", "Я ЛЮБЛЮ БОРЩ")) would behave as expected (throw a validation error)
as for defects/errors, throwing an exception inside a .map in ZIO is translated to a defect (e.g. ZIO.succeed(1).map(_ => throw new IllegalArgumentException(""))). That's just how ZIO works ... but as we want to represent any exceptions that happen during request construction as errors, I think that all ZIO backends should override .send and additionaly do:
.catchSomeDefect {
case e: Exception => ZIO.fail(e)
}
Reproducer
Requires
"com.softwaremill.sttp.client3" %% "zio" % "3.8.15"
Scastie link to the same code.
Actual console output:
Expectation:
While non-latin header values are forbidden, it's confusing that such an error is a ZIO defect.
What is more confusing is that sttp doesn't provide a proper way to validate the header value.
Therefore, there is no way to overcome this error easily.
I'd expect there is a way to either validate the header or handle such errors as ZIO's errors, because the header value may be a user input (therefore, it may be incorrect).
Is there any reason why this invalid header value isn't handled as "normal" error, but as a defect?
The text was updated successfully, but these errors were encountered: