Skip to content

Commit

Permalink
♻️ :: 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
jyk1029 committed Nov 9, 2023
1 parent 97c2c0f commit d6f79ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.sharing.domain.feed.service

import com.example.sharing.domain.feed.domain.repository.FeedRepository
import com.example.sharing.domain.feed.presentation.dto.response.FeedElement
import com.example.sharing.domain.user.exception.UserInterestAreaNotFoundException
import com.example.sharing.domain.user.facade.UserFacade
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -14,6 +15,6 @@ class QueryFeedByInterestAreaService(
@Transactional(readOnly = true)
fun execute(): List<FeedElement> {
val user = userFacade.getCurrentUser()
return feedRepository.findAllByAddressNameContaining(user.interestArea!!)
return feedRepository.findAllByAddressNameContaining(user.interestArea?: throw UserInterestAreaNotFoundException.EXCEPTION)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.sharing.domain.user.exception

import com.example.sharing.global.error.exception.ErrorCode.*
import com.example.sharing.global.error.exception.SharingException

class UserInterestAreaNotFoundException: SharingException(USER_INTEREST_AREA_NOT_FOUND) {
companion object {
@JvmField
val EXCEPTION = UserInterestAreaNotFoundException()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum class ErrorCode(

USER_NOT_FOUND(404, "User Not Found"),
FEED_NOT_FOUND(404, "Feed Not Found"),
USER_INTEREST_AREA_NOT_FOUND(404, "User Interest Area Not Found"),

ALREADY_ACCOUNT_ID_EXISTS(409, "Already Account Id Exists"),

Expand Down

0 comments on commit d6f79ce

Please sign in to comment.