Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

슬랙 에러 메시지 전송 오류 #325

Closed
limehee opened this issue May 3, 2024 · 0 comments · Fixed by #329
Closed

슬랙 에러 메시지 전송 오류 #325

limehee opened this issue May 3, 2024 · 0 comments · Fixed by #329
Assignees
Labels
🐞 Bug 버그 제보 및 수정

Comments

@limehee
Copy link
Collaborator

limehee commented May 3, 2024

버그 설명

private List<LayoutBlock> createErrorBlocks(HttpServletRequest request, Exception e) {
        String httpMethod = request.getMethod();
        String requestUrl = request.getRequestURI();

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = (authentication == null || authentication.getName() == null) ? "anonymous" : authentication.getName();

        return Arrays.asList(
                section(section -> section.text(markdownText(":firecracker: *Server Error*"))),
                section(section -> section.fields(Arrays.asList(
                        markdownText("*User:*\n" + username),
                        markdownText("*Endpoint:*\n[" + httpMethod + "] " + requestUrl)
                ))),
                section(section -> section.text(markdownText("*Error Message:*\n" + e.getMessage().split(":")[1]))),
                section(section -> section.text(markdownText("*Stack Trace:*\n```" + Arrays.toString(e.getStackTrace()) + "```")))
        );
    }

위 코드 중 "e.getMessage().split(":")[1]"에서 사용자 정의 예외가 아닌 경우에 java.lang.ArrayIndexOutOfBoundsException 발생.

예상 결과

슬랙으로 Server Error에 대한 정보가 전송되어야 함.

실제 결과

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at page.clab.api.global.common.slack.application.SlackService.lambda$createErrorBlocks$3(SlackService.java:133) ~[!/:na]
at com.slack.api.model.block.Blocks.section(Blocks.java:99) ~[slack-api-model-1.39.0.jar!/:1.39.0]
at page.clab.api.global.common.slack.application.SlackService.createErrorBlocks(SlackService.java:133) ~[!/:na]
at page.clab.api.global.common.slack.application.SlackService.sendServerErrorNotification(SlackService.java:71) ~[!/:na]
at page.clab.api.global.handler.GlobalExceptionHandler.serverException(GlobalExceptionHandler.java:182) ~[!/:na]

시뮬레이션

일부 데이터 삽입간 문제로 인해 서버 에러가 발생하였으나, 에러 메시지가 슬랙으로 전송되지 않고 java.lang.ArrayIndexOutOfBoundsException가 발생함.

로그

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
        at page.clab.api.global.common.slack.application.SlackService.lambda$createErrorBlocks$3(SlackService.java:133) ~[!/:na]
        at com.slack.api.model.block.Blocks.section(Blocks.java:99) ~[slack-api-model-1.39.0.jar!/:1.39.0]
        at page.clab.api.global.common.slack.application.SlackService.createErrorBlocks(SlackService.java:133) ~[!/:na]
        at page.clab.api.global.common.slack.application.SlackService.sendServerErrorNotification(SlackService.java:71) ~[!/:na]
        at page.clab.api.global.handler.GlobalExceptionHandler.serverException(GlobalExceptionHandler.java:182) ~[!/:na]
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]

환경

OS: 라즈베리파이4 Ubuntu LTS 22.04

ETC

No response

@limehee limehee added the 🐞 Bug 버그 제보 및 수정 label May 3, 2024
@limehee limehee self-assigned this May 3, 2024
@limehee limehee changed the title 슬랙 에러메시지 전송 오류 슬랙 에러 메시지 전송 오류 May 4, 2024
@limehee limehee linked a pull request May 4, 2024 that will close this issue
@limehee limehee closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug 버그 제보 및 수정
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant