Skip to content

Commit

Permalink
feat : (#19) apply custom exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kangeunchan committed Jan 9, 2025
1 parent a2121fd commit beeb2f9
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package entry.dsm.gitauth.equusgithubauth.domain.report.query.service

import entry.dsm.gitauth.equusgithubauth.domain.report.entity.Report
import entry.dsm.gitauth.equusgithubauth.domain.report.exception.ReportNotFoundException
import entry.dsm.gitauth.equusgithubauth.domain.report.query.dto.response.ReportQueryResponse
import entry.dsm.gitauth.equusgithubauth.domain.report.query.repository.ReportQueryRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum class ErrorCode(
val status: Int,
val message: String,
) {
USER_NOT_FOUND(404, "사용자를 찾을 수 없습니다."),
USER_INFO_FETCH_ERROR(500, "GitHub 사용자 정보를 가져올 수 없습니다."),
AUTHORIZED_CLIENT_NOT_FOUND(400, "사용자에 대한 인증된 클라이언트를 찾을 수 없습니다."),
ORGANIZATION_MEMBERSHIP_ERROR(400, "사용자가 조직의 멤버가 아닙니다."),
Expand All @@ -15,4 +16,7 @@ enum class ErrorCode(
NOTICE_NOT_FOUND(404, "공지사항을 찾을 수 없습니다."),

REPORT_NOT_FOUND(404, "보고서를 찾을 수 없습니다."),

JWT_TOKEN_EXPIRED(401, "JWT 토큰이 만료되었습니다."),
JWT_TOKEN_INVALID(401, "JWT 토큰이 유효하지 않습니다."),
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package entry.dsm.gitauth.equusgithubauth.global.security.auth

import entry.dsm.gitauth.equusgithubauth.domain.user.entity.User
import entry.dsm.gitauth.equusgithubauth.domain.user.entity.repository.UserRepository
import entry.dsm.gitauth.equusgithubauth.global.security.auth.exception.UserNotFoundException
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.stereotype.Service
Expand All @@ -13,7 +14,7 @@ class AuthDetailsService(
override fun loadUserByUsername(githubId: String): UserDetails {
val user: User =
userRepository.findByGithubId(githubId)
?: throw IllegalArgumentException("User not found with githubId: $githubId")
?: throw UserNotFoundException

return AuthDetails(user)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package entry.dsm.gitauth.equusgithubauth.global.security.auth.exception

import entry.dsm.gitauth.equusgithubauth.global.exception.CustomException
import entry.dsm.gitauth.equusgithubauth.global.exception.ErrorCode

object UserNotFoundException : CustomException(ErrorCode.USER_NOT_FOUND)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import entry.dsm.gitauth.equusgithubauth.domain.user.entity.RefreshToken
import entry.dsm.gitauth.equusgithubauth.domain.user.entity.repository.RefreshTokenRepository
import entry.dsm.gitauth.equusgithubauth.domain.user.presentation.dto.response.TokenResponse
import entry.dsm.gitauth.equusgithubauth.global.security.auth.AuthDetailsService
import entry.dsm.gitauth.equusgithubauth.global.security.jwt.exception.JwtTokenExpiredException
import entry.dsm.gitauth.equusgithubauth.global.security.jwt.exception.JwtTokenInvalidException
import io.jsonwebtoken.Claims
import io.jsonwebtoken.ExpiredJwtException
import io.jsonwebtoken.Jwts
Expand Down Expand Up @@ -86,8 +88,8 @@ class JwtTokenProvider(
.body
} catch (e: Exception) {
when (e) {
is ExpiredJwtException -> throw IllegalArgumentException("토큰이 만료되었습니다.")
else -> throw IllegalArgumentException("유효하지 않은 토큰입니다.")
is ExpiredJwtException -> throw JwtTokenExpiredException
else -> throw JwtTokenInvalidException
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package entry.dsm.gitauth.equusgithubauth.global.security.jwt.exception

import entry.dsm.gitauth.equusgithubauth.global.exception.CustomException
import entry.dsm.gitauth.equusgithubauth.global.exception.ErrorCode

object JwtTokenExpiredException : CustomException(ErrorCode.JWT_TOKEN_EXPIRED)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package entry.dsm.gitauth.equusgithubauth.global.security.jwt.exception

import entry.dsm.gitauth.equusgithubauth.global.exception.CustomException
import entry.dsm.gitauth.equusgithubauth.global.exception.ErrorCode

object JwtTokenInvalidException : CustomException(ErrorCode.JWT_TOKEN_INVALID)

0 comments on commit beeb2f9

Please sign in to comment.