def isSuccess()

in membership-common/src/main/scala/com/gu/zuora/rest/SimpleClient.scala [32:47]


  def isSuccess(statusCode: Int) = statusCode >= 200 && statusCode < 300

  def parseJson[B](in: OKHttpResponse): \/[String, JsValue] = {
    if (isSuccess(in.code)) {
      (for {
        body <- Try(in.body().string)
        json <- Try(Json.parse(body))
      } yield json) match {
        case Success(v) => \/.r[String](v)
        case scala.util.Failure(e) => \/.l[JsValue](e.toString)
      }
    } else {
      val bodyStr = Try(in.body.string).toOption
      \/.l[JsValue](s"response with status ${in.code}, body:$bodyStr")
    }
  }