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

예외처리 관련 #57

Open
moonwonki opened this issue May 13, 2024 · 2 comments
Open

예외처리 관련 #57

moonwonki opened this issue May 13, 2024 · 2 comments

Comments

@moonwonki
Copy link

GlobalExceptionHandler를 통해서 에러 처리 핸들러를 구현했습니다.

일단 지금 현재로써는 총 4개의 에러를 만들었습니다.

엔티티가 없을 때 NoEntityException (404)
인증을 하지 않았을 때 ForbiddenException (403)
인증은 했으나 권한이 없을 때 NotAuthenticatedException (401)
그리고 통상적으로 써먹을 그냥 유저가 뭔가 잘못했을 때, TypicalException (400)

발생시키는 방법은

image

이렇게 하면 됩니다.
이렇게 하면 에러가 발생했을 때 다음과 같은 페이지가 등장합니다.

image

모든 상황에서 위 에러 페이지가 항상 뜨는 것은 아닙니다.
Spring Security에서 발생하는 에러들은 GlobalExceptionHandler가 작동하기 이전 단계에서 발생하기 때문에 아마 로그인창으로 이동하게 될 것입니다.

제가 일단 Category Service랑 몇몇 서비스들만 바꿨는데, 너무 많아서 다 못 바꿨습니다.

에러 메시지는 매개변수로 주는 스트링 문자열이 출력됩니다.

가장 걱정인 부분은
JS fetch로 가져오는 부분에서 과연 이 에러 페이지가 어떻게 작동할까 인데, 아직 테스트를 완전히 해보지는 못했습니다.

@moonwonki
Copy link
Author

가장 쉽게 에러페이지를 확인할 방법은 /profile/moonmincheol 과 같이 없는 유저의 profile을 불러올 때입니다.

@hightuv
Copy link

hightuv commented May 14, 2024

문민철 그는 대체..

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

No branches or pull requests

2 participants