Fast Fail for andThen-composed Endpoints does not work
- Dominant language
- Scala
- Stars
- 1.6k
- Forks
- 217
- PR merge metrics
- No merged PRs in 30d
Description
# Description
When composing two endpoints with the *andThen* operator, if the first endpoint does not match, the second one is still evaluated. In particular, a json-body is parsed despite authentication has failed.
# Steps to reproduce
```
import io.finch._
import io.finch.circe._
import io.circe.generic.auto._
import io.finch.syntax._
import com.twitter.io.Buf
case class Body(value: String)
val legalBody = """{"value": "test"}"""
val illegalBody = """{"val": "test"}"""
val authE = header("Authorization").handle{ case e: Error.NotPresent => Unauthorized(new Exception("Not Authorized")) }
val bodyE = jsonBody[Body]
val testendpoint = post(authE :: bodyE)
testendpoint(Input.post("/").withBody[Application.Json](Buf.Utf8(legalBody))).awaitValue()
testendpoint(Input.post("/").withBody[Application.Json](Buf.Utf8(illegalBody))).awaitValue()
```
# Expected Behavior
In both cases, the result should be:
`Option[com.twitter.util.Try[String :: Body :: shapeless.HNil]] = Some(Throw(java.lang.Exception: Not Authorized))`
# Actual Behavior
The results are:
```
Option[com.twitter.util.Try[String :: Body :: shapeless.HNil]] = Some(Throw(java.lang.Exception: Not Authorized))
Option[com.twitter.util.Try[String :: Body :: shapeless.HNil]] = Some(Throw(io.finch.Error$NotParsed: body cannot be converted to $read$Body: Attempt to decode value on failed cursor: DownField(value).))
```
Contributor guide
Assessment
This issue has not been assessed yet.