Skip to content

[PR] FIX: Issue #62 #332

Description

@oosuhada

core exceptions 이슈 해결 내용

수정 대상

backend/app/core/exceptions.py

해결한 이슈

1. HTTPException headers 누락

기존 _http_exception_to_response()HTTPException 또는 StarletteHTTPException을 프로젝트 표준 JSON 응답으로 변환하면서 원본 예외의 headers를 전달하지 않았습니다.

그 결과 아래와 같은 HTTP 표준/프레임워크 헤더가 누락될 수 있었습니다.

401 WWW-Authenticate
405 Allow
429/503 Retry-After

수정 후에는 exc.headersJSONResponse에 함께 전달하도록 변경했습니다.

headers = getattr(exc, "headers", None)

return JSONResponse(
    status_code=exc.status_code,
    content=...,
    headers=headers,
)

2. 에러 봉투 형태 해석 불일치

기존 _build_http_exception_response()detail이 dict일 때 detail.get("error") 값을 그대로 error_code로 사용했습니다.

하지만 프로젝트 표준 에러 봉투는 error가 문자열이 아니라 아래와 같은 dict 구조입니다.

{
  "error": {
    "code": "INVALID_JOB_ID",
    "detail": "UUID 형식이 아닙니다.",
    "field": "job_id",
    "retryable": false
  }
}

이 경우 기존 로직은 error.code를 읽지 못해 에러 코드가 잘못 변환될 수 있었습니다.

수정 후에는 detail["error"]가 dict인 경우 내부의 code, detail, field, retryable 값을 우선 사용하도록 변경했습니다.

raw_error = detail.get("error")
if isinstance(raw_error, dict):
    error_code = raw_error.get("code") or _default_error_code(exc.status_code)
    error_detail = raw_error.get("detail") or detail.get("detail")
    field = raw_error.get("field") or detail.get("field")
    retryable = raw_error.get("retryable", detail.get("retryable"))

검증

문법 검증을 통과했습니다.

py_compile 통과
- backend/app/core/exceptions.py

참고

별도 테스트 파일은 추가하지 않고, 실제 이슈 해결 코드는 backend/app/core/exceptions.py에만 반영했습니다.


Retroactive merge-linked issues

  • Closes #62

Originally authored by woovii000 as PR #71

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions