Skip to content

fix: Feign 에러 응답이 500으로 전파됨 (ErrorDecoder 미설정) #6

@gisu1102

Description

@gisu1102

현상

ticketing-api에서 user-service로 Feign 호출 시, user-service가 4xx 응답을 반환하면 ticketing-api가 500 Internal Server Error로 변환해서 클라이언트에 전파합니다.

curl -s "http://localhost:8083/event/1" -H "Authorization: Bearer <TOKEN>"
# → {"message":"[401] during [GET] to [http://localhost:8080/users] [UserFeignClient#getUser()]: ...","code":500}

기대 동작

  • user-service 401 → ticketing-api 401 반환
  • user-service 404 → ticketing-api 적절한 에러 반환
  • user-service 5xx → ticketing-api 502 또는 503 반환

원인

Feign의 기본 ErrorDecoder는 4xx/5xx 응답을 FeignException으로 던지고, 글로벌 예외 핸들러가 이를 500으로 처리합니다. 커스텀 ErrorDecoder가 설정되어 있지 않아 원본 HTTP 상태 코드가 유실됩니다.

수정 방안

Feign ErrorDecoder를 구현하여 원본 상태 코드를 보존:

@Component
public class FeignErrorDecoder implements ErrorDecoder {
    @Override
    public Exception decode(String methodKey, Response response) {
        return switch (response.status()) {
            case 401 -> new AuthenticationException("인증 실패");
            case 404 -> new NotFoundException("리소스를 찾을 수 없습니다");
            default -> new FeignException.errorStatus(methodKey, response);
        };
    }
}

관련 파일

  • codin-ticketing-api/src/main/java/.../domain/user/config/FeignClientConfig.java
  • codin-ticketing-api/src/main/java/.../domain/user/fegin/UserFeignClient.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions