in pan-domain-auth-play/src/main/scala/com/gu/pandomainauth/service/OAuth.scala [40:52]
def oAuthResponse[T](r: WSResponse)(block: JsValue => T): T = {
r.status match {
case errorCode if errorCode >= 400 =>
// try to get error if we received an error doc (Google does this)
val error = (r.json \ "error").asOpt[Error]
error.map { e =>
throw new OAuthException(s"Error when calling OAuth provider: ${e.message}")
}.getOrElse {
throw new OAuthException(s"Unknown error when calling OAuth provider [status=$errorCode, body=${r.body}]")
}
case normal => block(r.json)
}
}