aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-04-13 16:40:10 +0300
committerGravatar Vitaly Takmazov2022-04-13 16:40:10 +0300
commitdae1b7cd38fbdae22cdcf79fb9ea09e2ab640255 (patch)
tree11ece234551f721fd831e700a074328f537df24a /src
parentcde193ed381f8734701649fa6af6b77560c2682f (diff)
Handle email exceptions
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/service/UserServiceImpl.java34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java
index fd42048c..36f37d5e 100644
--- a/src/main/java/com/juick/service/UserServiceImpl.java
+++ b/src/main/java/com/juick/service/UserServiceImpl.java
@@ -28,7 +28,10 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
@@ -57,6 +60,8 @@ import java.util.UUID;
@Repository
public class UserServiceImpl extends BaseJdbcService implements UserService {
+ private static final Logger logger = LoggerFactory.getLogger("UserService");
+
@Value("${juick.admin_users:}")
List<String> adminUsers;
@@ -173,18 +178,23 @@ public class UserServiceImpl extends BaseJdbcService implements UserService {
@Nonnull
public User getUserByEmail(String email) {
if (StringUtils.isNotBlank(email)) {
- List<User> list = getJdbcTemplate().query(
- "SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen, " +
- "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified " +
- "FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
- "LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
- "LEFT JOIN emails e ON e.user_id = u.id " +
- "WHERE u.id = (SELECT DISTINCT user_id FROM emails WHERE email = ?)",
- new UserMapper(),
- email);
-
- if (!list.isEmpty())
- return list.get(0);
+ try {
+ List<User> list = getJdbcTemplate().query(
+ "SELECT DISTINCT u.id, u.nick, u.passw, u.banned, u.last_seen, " +
+ "COALESCE(f.fb_id, vk.vk_id, t.tg_id, e.user_id, 0) AS verified " +
+ "FROM users u LEFT JOIN facebook f ON f.user_id = u.id " +
+ "LEFT JOIN vk ON u.id = vk.user_id LEFT JOIN telegram t ON u.id = t.user_id " +
+ "LEFT JOIN emails e ON e.user_id = u.id " +
+ "WHERE u.id = (SELECT DISTINCT user_id FROM emails WHERE email = ?)",
+ new UserMapper(),
+ email);
+
+ if (!list.isEmpty())
+ return list.get(0);
+ } catch (DataIntegrityViolationException e) {
+ logger.warn("Data exception with email {}", email);
+ return AnonymousUser.INSTANCE;
+ }
}
return AnonymousUser.INSTANCE;
}