Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ConstraintViolationException in exception handler, all operations will get a new API response #2908

Open
gel-hidden opened this issue Feb 19, 2025 · 0 comments

Comments

@gel-hidden
Copy link

Describe the bug

Maybe related to #2483.

When using @ExceptionHandler(ConstraintViolationException::class), all operations will get the 400 API response.

To Reproduce
Using the following:

    implementation("org.springframework.boot", "spring-boot-starter-validation", "3.4.2")
    implementation("org.springdoc", "springdoc-openapi-starter-webmvc-ui", "2.8.5")
    implementation("org.springframework.boot", "spring-boot-starter-web", "3.4.2")

With this implementation:

@RestController
class HelloController {
    @GetMapping("/hello")
    fun hello(): String {
        return "Hello, world!"
    }
}

@ControllerAdvice
class HelloControllerAdvice {

   @ExceptionHandler(ConstraintViolationException::class)
   @ResponseStatus(HttpStatus.BAD_REQUEST)
   @ApiResponse(responseCode = "400", description = "Bad Request")
   fun constraintViolation(
       ex: ConstraintViolationException,
   ): String {
       TODO()
   }
}

Expected behavior
I would like to opt in to say that the operation actually could produce the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant