Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.66 KB | None | 0 0
  1. def insert(account: AccountModel): Future[Long] =
  2.     db.run((Accounts returning Accounts.map(_.id)) += account.copy(password = account.password.bcrypt)).recover {
  3.       case ex : SQLIntegrityConstraintViolationException =>
  4.         //TODO make this independent from actual DB
  5.         ex.getMessage.toLowerCase match {
  6.           case m if m.contains("FOREIGN KEY (`roleid`) REFERENCES `role` (`id`)") =>
  7.             throw ForeignKeyException(account.roleId.get, "roleid", "account")
  8.           case m if m.contains("duplicate") =>
  9.             throw DuplicateRecordException("account", account.email)
  10.           case _ => throw ex
  11.         }
  12.       case ex => throw ex
  13.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement