You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ConstraintViolationException are automatically handled by ReactiveConstraintViolationExceptionHandler
Actual Behavior
ConstraintViolationException are handled by ExceptionHandlingWebHandler
Steps to Reproduce the Problem
Use spring kofu setup
Add org.valiktor:valiktor-spring-boot-starter:0.12.0 to deps.
Send request which throws ConstraintViolationException
PS C:\Users\srawa> Invoke-RestMethod "http://localhost:8000/api/user" -Body $User2 -Method POST -ContentType "application/json" | ConvertTo-Json
Invoke-RestMethod: {"timestamp":"2020-07-19T14:17:47.153+00:00","path":"/api/user","status":500,"error":"Internal Server Error","message":"","requestId":"64027368-1","exception":"org.valiktor.ConstraintViolationException"}
Server logs:
2020-07-19 19:47:47.166 ERROR 13776 --- [ctor-http-nio-2] a.w.r.e.AbstractErrorWebExceptionHandler : [64027368-1] 500 Server Error for HTTP POST "/api/user"
org.valiktor.ConstraintViolationException: null
at io.nooblabs.eventmanagerbackend.User.validate(EventmanagerBackendApplication.kt:62) ~[main/:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ HTTP POST "/api/user" [ExceptionHandlingWebHandler]
Stack trace:
Example Code or Link to a Project
val app = reactiveWebApplication {
beans {
bean<UserHandler>()
bean(::routes)
}
webFlux {
port = if (profiles.contains("test")) 8081 else 8000
codecs {
string()
jackson()
}
}
}
data class User(
val login: String,
val name: String
) {
fun validate(): User {
_validate(this) {
validate(User::login)
.isNotBlank()
.hasSize(min = 4, max = 8)
validate(User::name)
.isNotBlank()
.hasSize(max = 32)
}
return this
}
}
class UserHandler {
suspend fun createApi(request: ServerRequest): ServerResponse {
return request.awaitBody<User>()
.validate()
.let { user -> ok().bodyValueAndAwait(user) }
}
}
fun routes(userHandler: UserHandler) = coRouter {
POST("/api/user", userHandler::createApi)
}
fun main() {
app.run()
}
Environment
Valiktor version: 0.12.0
JDK/JRE version: adopt-openj9-14.0.1
Platform/OS: Win 10
The text was updated successfully, but these errors were encountered:
For me this only happens when invoking API from JUnit using @WebFluxTest; it works with @SpringBootTest.
I've tried to inject Beans for ValiktorExceptionHandler and ReactiveConstraintViolationExceptionHandler, but it made things worse.
Expected Behavior
ConstraintViolationException
are automatically handled byReactiveConstraintViolationExceptionHandler
Actual Behavior
ConstraintViolationException
are handled byExceptionHandlingWebHandler
Steps to Reproduce the Problem
org.valiktor:valiktor-spring-boot-starter:0.12.0
to deps.ConstraintViolationException
Server logs:
Example Code or Link to a Project
Environment
The text was updated successfully, but these errors were encountered: