aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/UserServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index 84ff1ff5..cf1c838d 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -21,6 +21,7 @@ import com.juick.model.Message;
import com.juick.model.User;
import com.juick.model.AnonymousUser;
import com.juick.model.AuthResponse;
+import com.juick.util.UsernameTakenException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -108,7 +109,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Transactional
@Override
- public Optional<User> createUser(final String username, final String password) {
+ public Optional<User> createUser(final String username, final String password) throws UsernameTakenException {
KeyHolder holder = new GeneratedKeyHolder();
try {
getJdbcTemplate().update(
@@ -122,7 +123,7 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
},
holder);
} catch (DuplicateKeyException e) {
- return Optional.empty();
+ throw new UsernameTakenException();
}
int uid = holder.getKeys().size() > 1 ? (int)holder.getKeys().get("id") : holder.getKey().intValue();