diff --git a/src/main/scala/com/ing/wbaa/rokku/sts/Server.scala b/src/main/scala/com/ing/wbaa/rokku/sts/Server.scala index 641cf49..c24a054 100644 --- a/src/main/scala/com/ing/wbaa/rokku/sts/Server.scala +++ b/src/main/scala/com/ing/wbaa/rokku/sts/Server.scala @@ -22,13 +22,19 @@ object Server extends App { override protected[this] def redisSettings: RedisSettings = RedisSettings(system) - //Connects to Redis on startup and initializes indeces - initializeUserSearchIndex(redisPooledConnection) - registerTerminationCallback(() => { logger.info("Closing redis connection pool...") redisPooledConnection.close() }) + //Connects to Redis on startup and initializes indeces + try { + initializeUserSearchIndex(redisPooledConnection) + } catch { + case ex: RedisSecondaryIndexException => + logger.error(s"Unable to create index $UsersIndex. Error: ${ex.getMessage()}. Exiting...") + sys.exit(1) + } + }.startup } diff --git a/src/main/scala/com/ing/wbaa/rokku/sts/service/db/RedisModel.scala b/src/main/scala/com/ing/wbaa/rokku/sts/service/db/RedisModel.scala index 41b4628..ec8fe69 100644 --- a/src/main/scala/com/ing/wbaa/rokku/sts/service/db/RedisModel.scala +++ b/src/main/scala/com/ing/wbaa/rokku/sts/service/db/RedisModel.scala @@ -21,6 +21,8 @@ trait RedisModel extends Encryption { private val DuplicateIndexExceptionMsg = "Index already exists" + case class RedisSecondaryIndexException(message: String) extends Exception + object UserKey { def encode(username: Username): String = { s"$UserKeyPrefix${username.value}" @@ -89,7 +91,7 @@ trait RedisModel extends Encryption { case DuplicateIndexExceptionMsg => logger.info(s"Index ${UsersIndex} already exists. Continuing...") case _ => - logger.error(s"Unable to create index $UsersIndex. Error: ${exc.getMessage()}") + throw new RedisSecondaryIndexException(s"Unable to create index $UsersIndex. Error: ${exc.getMessage()}") } case exc: Exception => logger.error(s"Unable to create index $UsersIndex. Error: ${exc.getMessage()}")