def handleIdentityClientError()

in payment-failure/src/main/scala/com/gu/identity/paymentfailure/abtest/AutoSignInTest.scala [12:27]


  def handleIdentityClientError(err: IdentityClientError): Throwable =
    err match {
      // If the user is invalid for an auto sign-in token,
      // return an UserIneligibleForAbTest,
      // so that the BrazeEmailServiceWithAbTest will send them a regular email
      // If user not found, still attempt to send a regular email,
      // since it might be that the braze external id is a salesforce id instead of an identity id.
      case apiError: ApiError if apiError.isInvalidUser || apiError.isUserNotFound =>
        UserIneligibleForAbTest("user not eligible for auto sign-in token", Some(apiError))
      // Otherwise return a RuntimeException
      // The BrazeEmailServiceWithAbTest will propagate this error,
      // meaning the lambda will be invoked again
      // i.e. another attempt will be made to send the email to the reader
      // with the variant meta data
      case _ => new RuntimeException("unable to create auto sign-in token", err)
    }