Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# 🚩 연관 JIRA 이슈
jira issue url:

# 🚩 연관 이슈

# 🔂 변경 내역

# 🗣️ 리뷰 요구사항 (선택)
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import static com.devoops.Constants.INITIAL_PULL_REQUEST_COUNT;

import com.devoops.command.request.RepositoryCreateCommand;
import com.devoops.domain.entity.github.repo.GithubRepository;
import com.devoops.domain.entity.github.pr.PullRequests;
import com.devoops.domain.entity.github.repo.GithubRepository;
import com.devoops.domain.entity.user.User;
import com.devoops.dto.request.GithubRepoUrl;
import com.devoops.dto.request.RepositorySaveRequest;
import com.devoops.dto.response.GithubRepoInfoResponse;
import com.devoops.event.AnalyzeMyPrEvent;
import com.devoops.exception.GithubNotFoundException;
import com.devoops.exception.custom.GssException;
import com.devoops.exception.errorcode.ErrorCode;
import com.devoops.service.GitHubService;
import com.devoops.service.github.WebHookService;
import com.devoops.service.repository.RepositoryService;
Expand All @@ -30,11 +33,15 @@ public class RepositoryFacadeService {

@Transactional
public GithubRepository save(RepositorySaveRequest request, User user) {
GithubRepoUrl repoUrl = new GithubRepoUrl(request.url());
GithubRepository savedRepository = saveRepository(repoUrl, user);
webHookService.registerWebhook(user, savedRepository.getId());
eventPublisher.publishEvent(new AnalyzeMyPrEvent(repoUrl, user, this));
return savedRepository;
try {
GithubRepoUrl repoUrl = new GithubRepoUrl(request.url());
GithubRepository savedRepository = saveRepository(repoUrl, user);
webHookService.registerWebhook(user, savedRepository.getId());
eventPublisher.publishEvent(new AnalyzeMyPrEvent(repoUrl, user, this));
return savedRepository;
} catch (GithubNotFoundException githubNotFoundException) {
throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND);
}
Comment on lines +36 to +44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

원인 예외 보존 또는 로깅 고려

운영 트러블슈팅을 위해 원인 예외를 GssException에 첨부하거나 최소 로그로 남기는 것을 권장합니다. GssException이 cause를 받는 생성자/팩토리를 제공한다면 다음 형태가 바람직합니다: new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND, githubNotFoundException)

다음 스크립트로 GssException 생성자 시그니처를 확인해 주세요:

가능 시 적용 예:

-        } catch (GithubNotFoundException githubNotFoundException) {
-            throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND);
+        } catch (GithubNotFoundException githubNotFoundException) {
+            // cause를 보존하거나 적어도 로그로 남기는 것을 권장
+            throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND, githubNotFoundException);
         }

🏁 Script executed:

#!/bin/bash
# GssException 생성자/팩토리 확인
rg -nP -C3 '\bclass\s+GssException\b'
rg -nP -C2 'GssException\s*\('
rg -nP -C2 'of\s*\(\s*ErrorCode'

Length of output: 32063


GssException에 원인 예외를 전달할 수 있는 생성자 추가 및 적용 필요

현재 GssExceptionErrorCode만 받는 생성자만 제공되어 원인 예외(cause)를 보존할 수 없습니다. 로깅 또는 추후 디버깅을 위해 아래와 같이 수정이 필요합니다.

수정 사항:

  • gss-common/src/main/java/com/devoops/exception/custom/GssException.javaThrowable 원인 예외를 받는 생성자 추가
  • gss-api-app/src/main/java/com/devoops/service/facade/RepositoryFacadeService.java 등 예외를 던지는 모든 곳에 해당 생성자를 사용하여 cause를 전달

예시 코드:

// gss-common/src/main/java/com/devoops/exception/custom/GssException.java
public class GssException extends RuntimeException {
    private final ErrorCode errorCode;

    public GssException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode;
    }

    // 원인 예외 보존용 생성자 추가
    public GssException(ErrorCode errorCode, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.errorCode = errorCode;
    }

    // getter...
}
// gss-api-app/src/main/java/com/devoops/service/facade/RepositoryFacadeService.java
-        } catch (GithubNotFoundException githubNotFoundException) {
-            throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND);
+        } catch (GithubNotFoundException githubNotFoundException) {
+            // 원인 예외를 보존하여 추후 로깅/디버깅에 활용
+            throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND, githubNotFoundException);
         }
  • 대상 파일 및 위치
    • gss-common/src/main/java/com/devoops/exception/custom/GssException.java
    • gss-api-app/src/main/java/com/devoops/service/facade/RepositoryFacadeService.java: 라인 36–44 외 예외 처리부 전반

위 리팩터링을 통해 원인 예외가 손실되지 않고, 운영 중 발생한 오류를 보다 정확히 파악할 수 있습니다.

🤖 Prompt for AI Agents
In
gss-api-app/src/main/java/com/devoops/service/facade/RepositoryFacadeService.java
around lines 36–44 and in
gss-common/src/main/java/com/devoops/exception/custom/GssException.java, add a
GssException constructor that accepts (ErrorCode, Throwable) and use it when
rethrowing from the catch block so the original GithubNotFoundException is
preserved as the cause; update GssException to call
super(errorCode.getMessage(), cause) and set the errorCode field, then replace
throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND) with
throw new GssException(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND,
githubNotFoundException) (and apply same pattern to other locations that rethrow
GssException).

}

private GithubRepository saveRepository(GithubRepoUrl url, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class Save {
);
}

@Test
void 웹훅_등록_실패_시_애플리케이션_에러로_전환한다() {
User user = userGenerator.generate("김건우");
RepositorySaveRequest request = new RepositorySaveRequest("https://github.com/octocat/Hello-World");
mockingErrorWhenCreateWebHook();

assertThatThrownBy(() -> repositoryFacadeService.save(request, user))
.isInstanceOf(GssException.class)
.hasMessage(ErrorCode.REGISTRY_GITHUB_REPOSITORY_NOT_FOUND.getMessage());
}

@Test
void 레포지토리를_중복_저장할_수_없다() {
User user = userGenerator.generate("김건우");
Expand All @@ -79,6 +90,16 @@ private void mockingGithubClient() {
Mockito.when(gitHubClient.createWebhook(any(), any(), any(), any()))
.thenReturn(mockWebHookCreateResponse);
}

private void mockingErrorWhenCreateWebHook() {
GithubRepoInfoResponse mockResponse = new GithubRepoInfoResponse(123, "testName", "testUrl",
new OwnerResponse("김건우"));
WebHookCreateResponse mockWebHookCreateResponse = new WebHookCreateResponse(123);
Mockito.when(gitHubClient.getRepositoryInfo(anyString(), anyString(), anyString()))
.thenReturn(mockResponse);
Mockito.when(gitHubClient.createWebhook(any(), any(), any(), any()))
.thenThrow(new GithubNotFoundException("mocking error"));
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public enum ErrorCode {

//4XX
REGISTRY_GITHUB_REPOSITORY_NOT_FOUND(400, "입력한 깃허브 레포지토리를 등록할 수 없습니다"),
REPOSITORY_NOT_FOUND(400, "레포지토리를 찾을 수 없습니다"),
MALFORMED_GITHUB_REPOSITORY_URL(400, "잘못된 형식의 레포지토리 url입니다"),
UNAUTHORIZED_EXCEPTION(401, "잘못된 유저 접근입니다"),
Expand Down
Loading