Skip to content

Fast Fail for andThen-composed Endpoints does not work #978

@d-s-d

Description

@d-s-d

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).))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions