Skip to content

Commit 0447dea

Browse files
committed
feat: Slack 에러 발송 #106
- service 레이어에 있는 모든 메소드 catch에 slack 알림 전송기능 추가
1 parent 3369f64 commit 0447dea

File tree

5 files changed

+72
-0
lines changed

5 files changed

+72
-0
lines changed

default/src/main/java/org/dfbf/soundlink/domain/alert/service/AlertService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.dfbf.soundlink.domain.alert.repository.AlertRepository;
77
import org.dfbf.soundlink.global.exception.ErrorCode;
88
import org.dfbf.soundlink.global.exception.ResponseResult;
9+
import org.dfbf.soundlink.global.slack.service.SlackService;
910
import org.springframework.http.MediaType;
1011
import org.springframework.stereotype.Service;
1112
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@@ -21,6 +22,7 @@
2122
public class AlertService {
2223

2324
private final AlertRepository alertRepository;
25+
private final SlackService slackService;
2426

2527
// 60 * 1000 * 60 = 3,600,000{ms} = 1시간
2628
private static final Long DEFAULT_TIMEOUT = 60L * 1000 * 60;
@@ -54,6 +56,7 @@ public SseEmitter connectAlarm(Long id, String lastEventId) {
5456
.data("connect completed!!")
5557
);
5658
} catch (IOException e) {
59+
slackService.sendMsg(id, e.getMessage());
5760
log.error("Error sending ping", e);
5861
}
5962

@@ -98,6 +101,7 @@ public ResponseResult send(Long userId, String alertName, Object data) {
98101

99102
return new ResponseResult(ErrorCode.SUCCESS);
100103
} catch (IOException e) {
104+
slackService.sendMsg(data, e.getMessage());
101105
alertRepository.delete(userId, emitterId);
102106
return new ResponseResult(ErrorCode.BAD_REQUEST_STATUS, e.getMessage());
103107
}

default/src/main/java/org/dfbf/soundlink/domain/blocklist/service/BlockListService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.dfbf.soundlink.domain.user.repository.UserRepository;
1515
import org.dfbf.soundlink.global.exception.ErrorCode;
1616
import org.dfbf.soundlink.global.exception.ResponseResult;
17+
import org.dfbf.soundlink.global.slack.service.SlackService;
1718
import org.springframework.stereotype.Service;
1819

1920
import java.util.List;
@@ -25,6 +26,7 @@ public class BlockListService {
2526
private final BlockListQueryRepository blockListQueryRepository;
2627
private final UserRepository userRepository;
2728
private final BlockListRepository blockListRepository;
29+
private final SlackService slackService;
2830

2931
@Transactional
3032
public ResponseResult blockUser(Long userId, BlockReq req) {
@@ -54,16 +56,19 @@ public ResponseResult blockUser(Long userId, BlockReq req) {
5456
ErrorCode.SUCCESS
5557
);
5658
} catch (BlockedUserNotFound e) {
59+
slackService.sendMsg(req, e.getMessage());
5760
return new ResponseResult(
5861
ErrorCode.BLOCKED_USER_NOT_FOUND,
5962
e.getMessage()
6063
);
6164
} catch (BlockingUserNotFound e) {
65+
slackService.sendMsg(req, e.getMessage());
6266
return new ResponseResult(
6367
ErrorCode.BLOCKING_USER_NOT_FOUND,
6468
e.getMessage()
6569
);
6670
} catch (AlreadyBlockedUser e) {
71+
slackService.sendMsg(req, e.getMessage());
6772
return new ResponseResult(
6873
ErrorCode.ALREADY_BLOCKED_USER,
6974
e.getMessage()
@@ -84,6 +89,7 @@ public ResponseResult unblockUser(Long userId, Long blocklistId) {
8489
ErrorCode.SUCCESS
8590
);
8691
} catch (BlockingUserNotFound e) {
92+
slackService.sendMsg(blocklistId, e.getMessage());
8793
return new ResponseResult(
8894
ErrorCode.BLOCKING_USER_NOT_FOUND,
8995
e.getMessage()

default/src/main/java/org/dfbf/soundlink/domain/chat/service/ChatRoomService.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.dfbf.soundlink.global.exception.ResponseResult;
2828
import org.dfbf.soundlink.global.feign.chat.DevChatClient;
2929
import org.dfbf.soundlink.global.kafka.KafkaProducer;
30+
import org.dfbf.soundlink.global.slack.service.SlackService;
3031
import org.springframework.data.redis.core.RedisTemplate;
3132
import org.springframework.security.core.annotation.AuthenticationPrincipal;
3233
import org.springframework.stereotype.Service;
@@ -51,6 +52,7 @@ public class ChatRoomService {
5152
private final DevChatClient devChatClient;
5253
private final KafkaProducer kafkaProducer;
5354
private final UserStatusService userStatusService;
55+
private final SlackService slackService;
5456

5557
private static final String CHAT_REQUEST_KEY = "chatRequest";
5658
private static final String TOPIC = "alert-topic";
@@ -111,13 +113,17 @@ public ResponseResult saveRequestToRedis(Long requestUserId, Long emotionRecordI
111113

112114
return new ResponseResult(ErrorCode.SUCCESS);
113115
} catch (IllegalArgumentException e) {
116+
slackService.sendMsg(requestUserId, e.getMessage());
114117
log.info(e.getMessage());
115118
return new ResponseResult(ErrorCode.CHAT_REQUEST_SSE_FAILED);
116119
} catch (EmotionRecordNotFoundException e) {
120+
slackService.sendMsg(requestUserId, e.getMessage());
117121
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD, e.getMessage());
118122
} catch (UserNotFoundException e) {
123+
slackService.sendMsg(requestUserId, e.getMessage());
119124
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
120125
} catch (Exception e) {
126+
slackService.sendMsg(requestUserId, e.getMessage());
121127
return new ResponseResult(ErrorCode.CHAT_REQUEST_FAILED, e.getMessage());
122128
}
123129
}
@@ -144,11 +150,14 @@ public ResponseResult deleteRequestFromRedis(Long userId, Long emotionRecordId)
144150
}
145151

146152
} catch (EmotionRecordNotFoundException e) {
153+
slackService.sendMsg(userId, e.getMessage());
147154
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD);
148155
} catch (UserNotFoundException e) {
156+
slackService.sendMsg(userId, e.getMessage());
149157
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
150158
} catch (Exception e) {
151159
log.error(e.getMessage());
160+
slackService.sendMsg(userId, e.getMessage());
152161
return new ResponseResult(400, "Failed to delete the chat request.");
153162
}
154163
}
@@ -180,10 +189,13 @@ public ResponseResult requestRejected(Long responseUserId, ChatRejectDto chatRej
180189
}
181190

182191
} catch (EmotionRecordNotFoundException e) {
192+
slackService.sendMsg(chatRejectDto, e.getMessage());
183193
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD);
184194
} catch (UserNotFoundException e) {
195+
slackService.sendMsg(chatRejectDto, e.getMessage());
185196
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER);
186197
} catch (Exception e) {
198+
slackService.sendMsg(chatRejectDto, e.getMessage());
187199
log.error(e.getMessage());
188200
return new ResponseResult(400, "Failed to reject the chat request.");
189201
}
@@ -266,10 +278,13 @@ public ResponseResult createChatRoom(Long userId, Long recordId, String requestN
266278
return new ResponseResult(400, "ChatRequest not found or expired.");
267279
}
268280
} catch (EmotionRecordNotFoundException e) {
281+
slackService.sendMsg(userId, e.getMessage());
269282
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD, e.getMessage());
270283
} catch (NoUserDataException e) {
284+
slackService.sendMsg(userId, e.getMessage());
271285
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
272286
} catch (Exception e) {
287+
slackService.sendMsg(userId, e.getMessage());
273288
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
274289
}
275290
}
@@ -298,6 +313,7 @@ public ResponseResult closeChatRoom(@AuthenticationPrincipal Long userId, Long c
298313

299314
return new ResponseResult(ErrorCode.SUCCESS);
300315
} catch (Exception e) {
316+
slackService.sendMsg(userId, e.getMessage());
301317
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
302318
}
303319
}
@@ -324,6 +340,7 @@ public ResponseResult getChatRoomList(@AuthenticationPrincipal Long userId) {
324340
.toList();
325341
return new ResponseResult(ErrorCode.SUCCESS, chatRoomList);
326342
} catch (Exception e) {
343+
slackService.sendMsg(userId, e.getMessage());
327344
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
328345
}
329346
}
@@ -351,10 +368,13 @@ public ResponseResult getChatRoomInfo(Long chatRoomId, Long userId) {
351368
);
352369
return new ResponseResult(ErrorCode.SUCCESS, infoDto);
353370
} catch (ChatRoomNotFoundException e) {
371+
slackService.sendMsg(userId, e.getMessage());
354372
return new ResponseResult(ErrorCode.CHATROOM_NOT_FOUND, "채팅방을 찾을 수 없습니다.");
355373
}catch (UnauthorizedAccessException e) {
374+
slackService.sendMsg(userId, e.getMessage());
356375
return new ResponseResult(ErrorCode.CHAT_UNAUTHORIZED,"권한이 없습니다.");
357376
}catch (Exception e) {
377+
slackService.sendMsg(userId, e.getMessage());
358378
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, "채팅방 세부 정보를 가져오는 데 실패했습니다.");
359379
}
360380
}

default/src/main/java/org/dfbf/soundlink/domain/emotionRecord/service/EmotionRecordService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.dfbf.soundlink.global.comm.enums.Emotions;
2121
import org.dfbf.soundlink.global.exception.ErrorCode;
2222
import org.dfbf.soundlink.global.exception.ResponseResult;
23+
import org.dfbf.soundlink.global.slack.service.SlackService;
2324
import org.springframework.dao.DataAccessException;
2425
import org.springframework.data.domain.Page;
2526
import org.springframework.data.domain.PageRequest;
@@ -41,6 +42,7 @@ public class EmotionRecordService {
4142
private final SpotifyMusicRepository spotifyMusicRepository;
4243
private final EmotionRecordRepository emotionRecordRepository;
4344
private final UserRepository userRepository;
45+
private final SlackService slackService;
4446

4547
// private final EmotionRecordCacheService emotionRecordCacheService;
4648
private final ChatRoomRepository chatRoomRepository;
@@ -81,10 +83,13 @@ public ResponseResult saveEmotionRecordWithMusic(Long userId, EmotionRecordReque
8183

8284
return new ResponseResult(ErrorCode.SUCCESS);
8385
} catch (UserNotFoundException e) {
86+
slackService.sendMsg(request, e.getMessage());
8487
return new ResponseResult(ErrorCode.FAIL_TO_FIND_USER, e.getMessage());
8588
} catch (DataAccessException e) {
89+
slackService.sendMsg(request, e.getMessage());
8690
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
8791
} catch (Exception e) {
92+
slackService.sendMsg(request, e.getMessage());
8893
log.error("감정기록 저장 서버 에러 {}", e.getMessage());
8994
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
9095
}
@@ -109,8 +114,10 @@ public ResponseResult getEmotionRecordsByUserId(Long userId, int page, int size)
109114

110115
return new ResponseResult(ErrorCode.SUCCESS, EmotionRecordPageResponseDTO.fromPage(recordsPage, dtoList));
111116
} catch (DataAccessException e) {
117+
slackService.sendMsg(userId, e.getMessage());
112118
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
113119
} catch (Exception e) {
120+
slackService.sendMsg(userId, e.getMessage());
114121
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
115122
}
116123
}
@@ -135,8 +142,10 @@ public ResponseResult getEmotionRecordsByLoginId(String userTag, int page, int s
135142

136143
return new ResponseResult(ErrorCode.SUCCESS, EmotionRecordPageResponseDTO.fromPage(recordsPage, dtoList));
137144
} catch (DataAccessException e) {
145+
slackService.sendMsg(userTag, e.getMessage());
138146
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
139147
} catch (Exception e) {
148+
slackService.sendMsg(userTag, e.getMessage());
140149
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
141150
}
142151
}
@@ -156,6 +165,7 @@ public ResponseResult getEmotionRecordsExcludingUserIdByFilters(Long userId, Lis
156165
.map(e -> Emotions.valueOf(e.toUpperCase()))
157166
.toList();
158167
} catch (IllegalArgumentException e) {
168+
slackService.sendMsg(null, e.getMessage());
159169
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION, "잘못된 감정 값이 포함되어 있습니다.");
160170
}
161171
}
@@ -169,8 +179,10 @@ public ResponseResult getEmotionRecordsExcludingUserIdByFilters(Long userId, Lis
169179

170180
return new ResponseResult(ErrorCode.SUCCESS, EmotionRecordPageResponseDTO.fromPage(recordsPage, dtoList));
171181
} catch (DataAccessException e) {
182+
slackService.sendMsg(userId, e.getMessage());
172183
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
173184
} catch (Exception e) {
185+
slackService.sendMsg(userId, e.getMessage());
174186
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
175187
}
176188
}
@@ -184,10 +196,13 @@ public ResponseResult getEmotionRecord(Long userId, Long recordId) {
184196

185197
return new ResponseResult(ErrorCode.SUCCESS, EmotionRecordResponseWithOwnerDTO.fromEntity(records, userId));
186198
} catch (EmotionRecordNotFoundException e) {
199+
slackService.sendMsg(userId, e.getMessage());
187200
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD, e.getMessage());
188201
} catch (DataAccessException e) {
202+
slackService.sendMsg(userId, e.getMessage());
189203
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
190204
} catch (Exception e) {
205+
slackService.sendMsg(userId, e.getMessage());
191206
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
192207
}
193208
}
@@ -202,10 +217,13 @@ public ResponseResult getVideoIdBySpotifyId(String spotifyId) {
202217
String videoId = music.getVideoId();
203218
return new ResponseResult(ErrorCode.SUCCESS, videoId);
204219
} catch (SpotifyMusicNotFoundException e) {
220+
slackService.sendMsg(spotifyId, e.getMessage());
205221
return new ResponseResult(ErrorCode.FAIL_TO_FIND_SPOTIFY_MUSIC, e.getMessage());
206222
} catch (DataAccessException e) {
223+
slackService.sendMsg(spotifyId, e.getMessage());
207224
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
208225
} catch (Exception e) {
226+
slackService.sendMsg(spotifyId, e.getMessage());
209227
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
210228
}
211229
}
@@ -250,10 +268,13 @@ public ResponseResult updateEmotionRecord(Long recordId, EmotionRecordUpdateRequ
250268
);*/
251269
return new ResponseResult(ErrorCode.SUCCESS, responseDTO);
252270
} catch (EmotionRecordNotFoundException e) {
271+
slackService.sendMsg(recordId, e.getMessage());
253272
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD, e.getMessage());
254273
} catch (DataAccessException e) {
274+
slackService.sendMsg(recordId, e.getMessage());
255275
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
256276
} catch (Exception e) {
277+
slackService.sendMsg(recordId, e.getMessage());
257278
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
258279
}
259280
}
@@ -299,10 +320,13 @@ public ResponseResult deleteEmotionRecord(Long recordId) {
299320
}
300321
return new ResponseResult(ErrorCode.SUCCESS, "감정 기록이 성공적으로 삭제되었습니다.");
301322
} catch (EmotionRecordNotFoundException e) {
323+
slackService.sendMsg(recordId, e.getMessage());
302324
return new ResponseResult(ErrorCode.FAIL_TO_FIND_EMOTION_RECORD, e.getMessage());
303325
} catch (DataAccessException e) {
326+
slackService.sendMsg(recordId, e.getMessage());
304327
return new ResponseResult(ErrorCode.DB_ERROR, e.getMessage());
305328
} catch (Exception e) {
329+
slackService.sendMsg(recordId, e.getMessage());
306330
return new ResponseResult(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
307331
}
308332
}
@@ -316,6 +340,7 @@ private ResponseResult validateAndCreatePageable(int page, int size) {
316340
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("createdAt").descending());
317341
return new ResponseResult(ErrorCode.SUCCESS, pageable);
318342
} catch (IllegalArgumentException e) {
343+
slackService.sendMsg(page, e.getMessage());
319344
return new ResponseResult(ErrorCode.INVALID_PAGE_REQUEST, "페이지 요청 값이 잘못되었습니다.");
320345
}
321346
}

0 commit comments

Comments
 (0)