def asType: Future[T] = when(Status.Ok)
def when(status: Status): Future[T] =
futureResponse.map { resp ⇒
resp.body.getOrElse {
val message =
if (resp.status != status.code) s"The response has no typed body because the request was not successful (status = ${resp.status})."
else "The response has no typed body despite status 200."
throw new IllegalArgumentException(message)
}
}
}
extra: wrap all HTTP codes (e.g. 200 in Status.OK)
extra: wrap all HTTP codes (e.g. 200 in Status.OK)