in src/main/scala/com/gu/okhttp/SharedClient.scala [20:31]
def getResponseBodyIfSuccessful(apiName: String, response: Response): Try[String] = {
val responseBody = response.body().string()
response.body().close() //https://square.github.io/okhttp/4.x/okhttp/okhttp3/-response-body/#the-response-body-must-be-closed
if (!response.isSuccessful) {
val message = s"Received an unsuccessful response from $apiName. Response code: ${response.code()} | response body: ${responseBody}"
logger.warn(message)
Failure(ApiException(message))
} else {
logger.info(s"Received successful response from $apiName. Response code: ${response.code()}")
Success(responseBody)
}
}