Use ResponseStatusException in ArticleController
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.example.blog
|
||||
|
||||
import org.springframework.http.HttpStatus.*
|
||||
import org.springframework.web.bind.annotation.*
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/article")
|
||||
@@ -11,7 +13,7 @@ class ArticleController(private val repository: ArticleRepository) {
|
||||
|
||||
@GetMapping("/{slug}")
|
||||
fun findOne(@PathVariable slug: String) =
|
||||
repository.findBySlug(slug) ?: throw IllegalArgumentException("Wrong article slug provided")
|
||||
repository.findBySlug(slug) ?: throw ResponseStatusException(NOT_FOUND, "Wrong article slug provided")
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user