feat: アカウントが見つからなかった場合のエラーハンドリングを追加

This commit is contained in:
usbharu 2024-02-24 15:26:13 +09:00
parent 208d1c519a
commit 5fad278b0b
2 changed files with 7 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package dev.usbharu.hideout.mastodon.infrastructure.springweb
import dev.usbharu.hideout.domain.mastodon.model.generated.NotFoundResponse
import dev.usbharu.hideout.domain.mastodon.model.generated.UnprocessableEntityResponse
import dev.usbharu.hideout.domain.mastodon.model.generated.UnprocessableEntityResponseDetails
import dev.usbharu.hideout.mastodon.domain.exception.AccountNotFoundException
import dev.usbharu.hideout.mastodon.domain.exception.StatusNotFoundException
import dev.usbharu.hideout.mastodon.interfaces.api.account.MastodonAccountApiController
import dev.usbharu.hideout.mastodon.interfaces.api.apps.MastodonAppsApiController
@ -98,6 +99,12 @@ class MastodonApiControllerAdvice {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getTypedResponse().response)
}
@ExceptionHandler(AccountNotFoundException::class)
fun handleException(ex: AccountNotFoundException): ResponseEntity<NotFoundResponse> {
logger.warn("Account not found.", ex)
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getTypedResponse().response)
}
companion object {
private val logger = LoggerFactory.getLogger(MastodonApiControllerAdvice::class.java)
}

View File

@ -152,7 +152,6 @@ class AccountApiServiceImpl(
return@transaction accountService.findById(id)
}
} catch (e: UserNotFoundException) {
logger.debug("Account Not found $id")
throw AccountNotFoundException.ofId(id)
}
}