Use ResponseStatusException in ArticleController

This commit is contained in:
Sebastien Deleuze
2019-10-18 09:44:09 +02:00
parent d9316a6db2
commit 7eee601971

View File

@@ -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")
}