You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would the following functions be helpful to add to http4k-core? If so, I can submit a PR. If not, I can keep them as extension functions. However, it seems like they might be useful to others (perhaps with some changes to the Exceptions that are thrown, such as using IllegalArgumentException or IllegalStateException).
/** * Throws an [InvalidInputException] if the [response][Response] [status][Status] is * [400][Status.BAD_REQUEST]. Otherwise, apply the [BiDiBodyLens] to the [response][Response]. * * @see validate*/
@Throws(InvalidInputException::class)
fun <FINAL> BiDiBodyLens<FINAL>.getOrThrow(response:Response): FINAL {
if (response.status ==Status.BAD_REQUEST) throwInvalidInputException(response.body.toString())
response.validate()
returnthis(response)
}
/** * If the [response][Response] is [204][Status.NO_CONTENT], return `null`. Otherwise, apply the * [BiDiBodyLens] to the [response][Response]. * * @see validate*/fun <FINAL> BiDiBodyLens<FINAL>.optional(response:Response): FINAL? {
response.validate()
returnif (response.status ==Status.NO_CONTENT) nullelsethis(response)
}
/** * If the [response][Response] is [204][Status.NO_CONTENT], return an empty [List][emptyList]. * Otherwise, apply the [BiDiBodyLens] to the [response][Response]. * * @see validate*/fun <FINAL> BiDiBodyLens<List<FINAL>>.optional(response:Response): List<FINAL> {
response.validate()
returnif (response.status ==Status.NO_CONTENT) emptyList() elsethis(response)
}
/** * Throws a [ResponseException] if the [Response] [status][Status] is not [200][Status.OK] or * [204][Status.NO_CONTENT].*/
@Throws(ResponseException::class)
fun Response.validate() {
if (status !inlistOf(Status.OK, Status.NO_CONTENT)) throwResponseException(status)
}
The text was updated successfully, but these errors were encountered:
Would the following functions be helpful to add to http4k-core? If so, I can submit a PR. If not, I can keep them as extension functions. However, it seems like they might be useful to others (perhaps with some changes to the Exceptions that are thrown, such as using
IllegalArgumentException
orIllegalStateException
).The text was updated successfully, but these errors were encountered: