Skip to content

bug: 엑셀이 아닌 파일 업로드가 500을 반환하는 문제 (#79) - #80

Merged
cowtree28 merged 1 commit into
developfrom
bug/79-non-excel-upload-500
Oct 6, 2026
Merged

cowtree28 merged 1 commit into
developfrom
bug/79-non-excel-upload-500

Conversation

@cowtree28

@cowtree28 cowtree28 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

개요

확장자만 .xlsx로 바꾼 비엑셀 파일을 업로드하면 500이 나던 것을 400 + 행동 가능한 메시지로 고친다.

Closes #79

운영 재현 (수정 전)

POST /api/files/upload
file: "기간제 근로자 관리서식.hwpx.xlsx"   (HWPX를 .xlsx로 이름만 변경)

HTTP/2 500
{"code":"INTERNAL_SERVER_ERROR","status":500,"message":"서버 에러입니다."}

FE가 서버 장애로 판단했고, 사용자는 무엇을 고쳐야 하는지 알 수 없었다. 실제로는 파일을 변환해 오면 되는 상황이다.

원인

1. FileValidator를 통과한다. 확장자와 ZIP 매직넘버(50 4B 03 04)만 검사하는데, HWPX도 ZIP 컨테이너라 둘 다 통과한다.

2. ExcelParser가 POI의 런타임 예외를 잡지 않았다. IOException만 잡는데 POI는 전부 RuntimeException 계열로 던진다.

입력 POI 예외 기존 처리
HWPX 유사 ZIP org.apache.poi.ooxml.POIXMLException
("Package should contain a content type part [M1.13]")
❌ → 500
0바이트 org.apache.poi.EmptyFileException ❌ → 500

변경 내용

워크북을 여는 일만 하는 openWorkbook()을 분리해 거기서 POI 예외를 FileException으로 매핑했다. 이 메서드는 워크북 생성만 하므로 우리가 던진 FileException을 삼킬 위험이 없다 — 그래서 RuntimeException을 통째로 잡아도 안전하고, POI가 버전에 따라 다른 예외 타입을 던져도 새지 않는다.

private static Workbook openWorkbook(InputStream inputStream) {
    try {
        return new XSSFWorkbook(inputStream);
    } catch (EmptyFileException e) {
        throw new FileException(FileErrorCode.UNPROCESSABLE_FILE);
    } catch (IOException | RuntimeException e) {
        throw new FileException(FileErrorCode.NOT_AN_EXCEL_FILE);
    }
}

FileErrorCode.NOT_AN_EXCEL_FILE(400)을 추가했다. 메시지는 다음에 할 행동을 담았다.

엑셀 파일이 아닙니다. 확장자만 .xlsx로 바꾼 파일(한글 .hwpx 등)은 업로드할 수 없습니다. 엑셀에서 「다른 이름으로 저장 → Excel 통합 문서(.xlsx)」로 변환해 주세요.

부수 효과

MappingConfirmService가 저장된 파일을 다시 파싱하는 경로도 같이 막힌다. 그쪽은 FileValidator를 거치지 않아 같은 500 경로가 열려 있었다.

테스트

ExcelParserInvalidInputTest 5개 추가. 전체 125개 통과.

HWPX 유사 ZIP이 ZIP 매직넘버 검사를 통과한다는 전제 자체를 단언해 고정했고, 마지막 테스트는 네 가지 잘못된 입력 전부에 대해 처리되지 않은 런타임 예외가 새지 않는다는 것을 확인한다.

FE에 전달할 것

이 PR이 머지돼도 해당 파일은 여전히 업로드되지 않는다 — 엑셀 파일이 아니기 때문이다. 달라지는 건 500 대신 400과 변환 방법 안내를 받는 것이다.

기간제 근로자 관리서식.hwpx.xlsx는 한글 문서를 이름만 바꾼 것으로 보인다. 엑셀에서 열어 .xlsx로 다시 저장한 파일이 필요하다.

참고 — 함께 확인한 것

운영 에러 응답에 CORS 헤더가 정상으로 붙는다(access-control-allow-origin, access-control-expose-headers: Content-Disposition). #32의 "에러 응답에 CORS 헤더 누락"은 현재 재현되지 않는다 — #60/#43으로 해소된 것으로 보인다.

Summary by CodeRabbit

  • Bug Fixes
    • Invalid files uploaded as Excel spreadsheets now receive a clear error instead of causing an unexpected failure. This includes files renamed to .xlsx without being converted to an Excel workbook.
    • Empty files are identified separately and reported as unprocessable.

@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c01f2cc4-a63f-413a-aa28-e416ec2c46ed
📥 Commits

Reviewing files that changed from the base of the PR and between ca55da6 and 0705b6a.

📒 Files selected for processing (3)
  • src/main/java/commonly/commonlybe/file/excel/ExcelParser.java
  • src/main/java/commonly/commonlybe/global/error/error_code/FileErrorCode.java
  • src/test/java/commonly/commonlybe/file/excel/ExcelParserInvalidInputTest.java
 ___________________________________________
< I am a verified code reviewer on Twitter. >
 -------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cowtree28
cowtree28 merged commit b10649f into develop Oct 6, 2026
1 of 2 checks passed
@cowtree28
cowtree28 deleted the bug/79-non-excel-upload-500 branch October 6, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

확장자만 .xlsx로 바꾼 파일 업로드가 500을 반환한다

1 participant