Skip to content

Provide more flexible handling of the asType extension method (Scala only) #119

@rigolepe

Description

@rigolepe
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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions