def handleErrorResponse()

in eventbrite-consents/src/main/scala/com/gu/identity/eventbriteconsents/clients/IdentityClient.scala [28:45]


  def handleErrorResponse(code: Int, body: String, emailAddress: String): Unit = {
    parse(body).flatMap(_.as[IdapiErrorResponse]) match {
      case Right(errorResponse: IdapiErrorResponse) => {
        for {
          error <- errorResponse.errors
        } yield if (error.description.contains("Bad email format")) {
          logger.error("Invalid email address, could not process consents: " + emailAddress)
        } else {
          throwRuntimeException()
        }
      }
      case _ => throwRuntimeException()
    }

    def throwRuntimeException(): Nothing = {
      throw new RuntimeException(s"Unexpected response from idapi when syncing email $emailAddress $code $body")
    }
  }