From 7a0d3dd41ef58fb3526d68f1776fed5650963b30 Mon Sep 17 00:00:00 2001 From: yang Date: Sun, 16 Jun 2024 02:06:22 +0900 Subject: [PATCH] =?UTF-8?q?RAC-399=20feat=20:=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=ED=86=A1=20=EB=B0=9C=EC=86=A1=20=EC=8B=A4=ED=8C=A8=EC=8B=9C=20?= =?UTF-8?q?=EC=8A=AC=EB=9E=99=20=EC=95=8C=EB=A6=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/usecase/BizppurioSend.java | 7 ++++- .../global/slack/SlackErrorMessage.java | 30 +++++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java index e2f0fab0..0fb1e695 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.global.bizppurio.application.dto.req.CommonRequest; import com.postgraduate.global.bizppurio.application.dto.res.MessageResponse; +import com.postgraduate.global.slack.SlackErrorMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -20,6 +21,7 @@ public class BizppurioSend { private final BizppurioAuth bizppurioAuth; private final ObjectMapper objectMapper; private final WebClient webClient; + private final SlackErrorMessage slackErrorMessage; @Value("${bizppurio.message}") private String messageUrl; @@ -39,13 +41,16 @@ protected void sendMessageWithExceptionHandling(Supplier messageS .subscribe(this::check); } catch (Exception ex) { log.error("알림톡 전송 예외 발생: {}", ex.getMessage()); + CommonRequest commonRequest = messageSupplier.get(); + String phoneNumber = commonRequest.to(); + slackErrorMessage.sendSlackBizppurioError(phoneNumber); } } private void check(MessageResponse response) { if (response.code() != 1000) { log.error("전송실패 errorCode : {} errorMessage : {}", response.code(), response.description()); - return; + throw new IllegalArgumentException(response.code() + ", " + response.description()); } log.info("알림톡 전송에 성공하였습니다."); } diff --git a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java index b50e130e..fa9bdea3 100644 --- a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java +++ b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java @@ -1,6 +1,5 @@ package com.postgraduate.global.slack; -import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.slack.api.Slack; import com.slack.api.model.Attachment; import com.slack.api.webhook.Payload; @@ -25,12 +24,12 @@ public class SlackErrorMessage { @Value("${slack.log_url}") private String logWebHookUrl; - public void sendSlackError(Mentoring mentoring, Exception ex) { + public void sendSlackMentoringError(Long mentoringId, Throwable ex) { try { slackClient.send(logWebHookUrl, Payload.builder() - .text("자동 갱신 에러 발생!! 백엔드팀 확인 요망!!") + .text("멘토링 자동 갱신 에러 발생!! 백엔드팀 확인 요망!!") .attachments( - List.of(generateErrorSlackAttachment(mentoring, ex)) + List.of(generateMentoringErrorSlackAttachment(mentoringId, ex)) ) .build()); } catch (IOException e) { @@ -38,12 +37,12 @@ public void sendSlackError(Mentoring mentoring, Exception ex) { } } - public void sendSlackMentoringError(Long mentoringId, Throwable ex) { + public void sendSlackSalaryError(Long seniorId, Throwable ex) { try { slackClient.send(logWebHookUrl, Payload.builder() - .text("멘토링 자동 갱신 에러 발생!! 백엔드팀 확인 요망!!") + .text("정산 자동 생성 에러 발생!! 백엔드팀 확인 요망!!") .attachments( - List.of(generateMentoringErrorSlackAttachment(mentoringId, ex)) + List.of(generateSalaryErrorSlackAttachment(seniorId, ex)) ) .build()); } catch (IOException e) { @@ -51,12 +50,12 @@ public void sendSlackMentoringError(Long mentoringId, Throwable ex) { } } - public void sendSlackSalaryError(Long seniorId, Throwable ex) { + public void sendSlackBizppurioError(String phoneNumber) { try { slackClient.send(logWebHookUrl, Payload.builder() - .text("정산 자동 생성 에러 발생!! 백엔드팀 확인 요망!!") + .text("알림톡 발송 실패! 확인 요망!!") .attachments( - List.of(generateSalaryErrorSlackAttachment(seniorId, ex)) + List.of(generateBizppurioErrorSlackAttachment(phoneNumber)) ) .build()); } catch (IOException e) { @@ -76,26 +75,25 @@ private Attachment generateMentoringErrorSlackAttachment(Long mentoringId, Throw .build(); } - private Attachment generateErrorSlackAttachment(Mentoring mentoring, Exception ex) { + private Attachment generateSalaryErrorSlackAttachment(Long seniorId, Throwable ex) { String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now()); return Attachment.builder() .color("ff0000") .title(requestTime + "에 발생한 에러 로그") .fields(List.of( generateSlackField("Error Message", ex.getMessage()), - generateSlackField("Mentoring 번호", String.valueOf(mentoring.getMentoringId())) + generateSlackField("정산 자동 생성 실패, 선배 번호", String.valueOf(seniorId)) )) .build(); } - private Attachment generateSalaryErrorSlackAttachment(Long seniorId, Throwable ex) { + private Attachment generateBizppurioErrorSlackAttachment(String phoneNumber) { String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now()); return Attachment.builder() .color("ff0000") - .title(requestTime + "에 발생한 에러 로그") + .title(requestTime + "에 발생한 알림톡 발송 실패") .fields(List.of( - generateSlackField("Error Message", ex.getMessage()), - generateSlackField("정산 자동 생성 실패, 선배 번호", String.valueOf(seniorId)) + generateSlackField("알림톡 발송 실패, 수신 번호", phoneNumber) )) .build(); }