Skip to content

Commit

Permalink
fix: FCM 예외 처리 (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
helenason authored and fromitive committed Nov 28, 2024
1 parent 073479b commit 3d9249e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private MemberEntity signup(AuthProvider provider, String loginId, String fcmTok
}

private MemberEntity createMember(AuthProvider provider, String loginId, String fcmToken, String password) {
if (fcmToken == null) {
if (fcmToken == null || fcmToken.isEmpty()) {
return new MemberEntity(nickNameGenerator.generate(), provider, loginId, password);
}
return new MemberEntity(nickNameGenerator.generate(), provider, loginId, password, fcmToken);
Expand All @@ -62,7 +62,7 @@ private AuthInfoDto login(MemberEntity member, String fcmToken) {
}

private void checkFcmToken(MemberEntity member, String fcmToken) {
if (fcmToken == null) {
if (fcmToken == null || fcmToken.isEmpty()) {
member.updateFcmTokenDefault();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public BatchResponse send(MulticastMessage message) {
log.info("알림 메시지 전송 성공 개수: {}", response.getSuccessCount());
log.info("알림 메시지 전송 실패 개수: {}", response.getFailureCount());
return response;
} catch (FirebaseMessagingException e) {
} catch (FirebaseMessagingException | IllegalArgumentException e) {
return sendWhenFailWithBatch(e);
}
}

private String sendWhenFail(FirebaseMessagingException e) {
private String sendWhenFail(Exception e) {
if (isInvalidToken(e)) {
log.error("알림 메시지 전송 실패: {}", "유효하지 않은 토큰");
return "";
Expand All @@ -52,7 +52,7 @@ private String sendWhenFail(FirebaseMessagingException e) {
throw new MarketException(NotificationErrorCode.CANNOT_SEND_ALARM);
}

private BatchResponse sendWhenFailWithBatch(FirebaseMessagingException e) {
private BatchResponse sendWhenFailWithBatch(Exception e) {
if (isInvalidToken(e)) {
log.error("알림 메시지 전송 실패: {}", "유효하지 않은 토큰");
return null;
Expand All @@ -62,7 +62,7 @@ private BatchResponse sendWhenFailWithBatch(FirebaseMessagingException e) {
throw new MarketException(NotificationErrorCode.CANNOT_SEND_ALARM);
}

private boolean isInvalidToken(FirebaseMessagingException e) {
private boolean isInvalidToken(Exception e) {
return e.getMessage().contains(ERROR_MESSAGE_WHEN_INVALID_TOKEN)
|| e.getMessage().contains(ERROR_MESSAGE_WHEN_OLD_TOKEN)
|| e.getMessage().contains(ERROR_MESSAGE_WHEN_TOKEN_EMPTY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public TopicManagementResponse subscribe(MemberEntity member, FcmTopic topic) {
log.info("구독 성공 개수: {}", response.getSuccessCount());
log.info("구독 실패 개수: {}", response.getFailureCount());
return response;
} catch (FirebaseMessagingException e) {
} catch (FirebaseMessagingException | IllegalArgumentException e) {
return subscribeWhenFail(e);
}
}
Expand All @@ -41,12 +41,12 @@ public TopicManagementResponse unsubscribe(MemberEntity member, FcmTopic topic)
log.info("구독 취소 성공 개수: {}", response.getSuccessCount());
log.info("구독 취소 실패 개수: {}", response.getFailureCount());
return response;
} catch (FirebaseMessagingException e) {
} catch (FirebaseMessagingException | IllegalArgumentException e) {
return subscribeWhenFail(e);
}
}

private TopicManagementResponse subscribeWhenFail(FirebaseMessagingException e) {
private TopicManagementResponse subscribeWhenFail(Exception e) {
if (isInvalidToken(e)) {
log.error("토픽 구독 실패: {}", "유효하지 않은 토큰");
return null;
Expand All @@ -56,7 +56,7 @@ private TopicManagementResponse subscribeWhenFail(FirebaseMessagingException e)
throw new MarketException(NotificationErrorCode.CANNOT_SEND_ALARM);
}

private boolean isInvalidToken(FirebaseMessagingException e) {
private boolean isInvalidToken(Exception e) {
return e.getMessage().contains(ERROR_MESSAGE_WHEN_INVALID_TOKEN)
|| e.getMessage().contains(ERROR_MESSAGE_WHEN_OLD_TOKEN)
|| e.getMessage().contains(ERROR_MESSAGE_WHEN_TOKEN_EMPTY)
Expand Down

0 comments on commit 3d9249e

Please sign in to comment.