Skip to content

Commit

Permalink
Merge pull request #288 from WE-ARE-RACCOONS/RAC-399
Browse files Browse the repository at this point in the history
RAC-399 feat : μ•Œλ¦Όν†‘ λ°œμ†‘ μ‹€νŒ¨μ‹œ μŠ¬λž™ μ•Œλ¦Ό μΆ”κ°€
  • Loading branch information
ywj9811 authored Jun 15, 2024
2 parents 93095c3 + 7a0d3dd commit 22044bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,13 +41,16 @@ protected void sendMessageWithExceptionHandling(Supplier<CommonRequest> 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("μ•Œλ¦Όν†‘ 전솑에 μ„±κ³΅ν•˜μ˜€μŠ΅λ‹ˆλ‹€.");
}
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,38 +24,38 @@ 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) {
log.error("slack 전솑 였λ₯˜");
}
}

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) {
log.error("slack 전솑 였λ₯˜");
}
}

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) {
Expand All @@ -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();
}
Expand Down

0 comments on commit 22044bd

Please sign in to comment.