I am using spring-webflux, and in some error cases I throw a ResponseStatusException using 2 parameters constructor : a HttpStatus and a reason (String). Code is written in Kotlin
// NotFoundStatusException is simply a subclass of ResponseStatusException
internal class NotFoundStatusException(reason: String? = null) : ResponseStatusException(HttpStatus.NOT_FOUND, reason)
repository.findByName(name)
.switchIfEmpty { Mono.error(NotFoundStatusException("No Cow found for $name name")) }
An API integration test verify that JSON in this error case is correct
assertThat(error["message"] as String).isEqualTo("No Cow found for $name name")
This test is working fine with spring-boot 2.2.7, but this fails with spring-boot 2.3.0.
To reproduce, just clone my demo-kotlin repository, all tests are passing because it is currently configured with spring-boot 2.2.7. Change spring_boot_plugin_version to 2.3.0.RELEASE in gradle.properties, now some tests are failing because message field in error JSON body is empty :
Expecting:
<"">
to be equal to:
<"No Cow found for no-name name">
but was not.
{"timestamp":"2020-05-18T19:28:19.060+00:00","path":"/api/cows/name/no-name","status":404,"error":"Not Found","message":"","requestId":"ffef802b-5"}
Comment From: scottfrederick
This is an intentional change in 2.3.0
. Please see the release notes for more information.
Comment From: scottfrederick
Duplicate of #21469
Comment From: pull-vert
Thanks a lot !