Skip to content

Commit

Permalink
[CHORE] 디스코드 알람시에 실행 환경 확인 가능하게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi committed Mar 5, 2024
1 parent 150d353 commit f257ce1
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

Expand All @@ -18,6 +19,7 @@ public class DiscordAlarmSender {

private final ObjectMapper objectMapper;
private final ValueConfig valueConfig;
private final Environment environment;

public void send(final String content, final DiscordAlarmCase alarmCase) {
try {
Expand All @@ -35,10 +37,17 @@ public void send(final String content, final DiscordAlarmCase alarmCase) {
}

private String makeRequestBody(String content) throws JsonProcessingException {
val request = DiscordRequest.of(content);
val request = DiscordRequest.of("[" + getCurrentProfile() + "] : " + content);
return objectMapper.writeValueAsString(request);
}

private String getCurrentProfile() {
if (environment.getActiveProfiles().length == 0) {
return "default";
}
return environment.getActiveProfiles()[0];
}

private String webHookUri(DiscordAlarmCase alarmCase) {
return switch (alarmCase) {
case ERROR -> valueConfig.getDISCORD_WEBHOOK_ERROR_URL();
Expand Down

0 comments on commit f257ce1

Please sign in to comment.