Hello all,
Im using spray client and what I'd like to do after a get request is to take the response code and return an optional type; however I keep running into a brick wall, and I am not sure what Im doing incorrectly. Could some please point me in the right direction
This is the code I have so far :
val pipeline: HttpRequest => Future[HttpResponse] = (
addHeader(HttpHeaders.`Content-Type`.apply(ContentTypes.`application/json`))
~> sendReceive ~> transformerOption[EditorError]
)
My transformer looks like this:
def transformerOption[CustomError]: Future[HttpResponse] => Future[Option[CustomError]] =
(futRes: Future[HttpResponse]) => futRes.map { res =>
if (res.status == StatusCodes.NotFound) {
Some(CustomError(res.status.defaultMessage, "some string here"))
} else if (res.status == StatusCodes.NotFound) {
Some(CustomError(res.status.defaultMessage, "some other string here"))
} else {
None
}
}
I've defined my type and the case codec like so:
case class CustomError(name: String, details: String)
implicit def CustomErrorCodec: CodecJson[CustomError] =
casecodec2(CustomError.apply, CustomError.unapply)("name", "details")
I'd appreciate any help here with this. Thanks for taking the time to look.
Cheers