Closed
Description
@RestController
@Validated
class DemoController {
@GetMapping("/{message}")
String fails(@PathVariable("message") @Size(min = 3) String message) {
return "Message is " + message;
}
@PostMapping
String works(@Validated @RequestBody RequestDto message) {
return "Message is " + message.getMessage();
}
}
class RequestDto {//getters setters omitted
@Size(min = 3)
private String message;
}
When validating @PathVariable
s as shown above it gives 500 instead of 400. I think this is both wrong and unintuitive because this is a similar case when we validate @RequestBody
s which give 400 when validation fails.
response of fails
method when validation fails:
{
"timestamp": 1506928557130,
"status": 500,
"error": "Internal Server Error",
"message": "No message available",
"path": "/a"
}
response of works
method when validation fails:
{
"timestamp": 1506928056306,
"status": 400,
"error": "Bad Request",
"errors": [
{
"codes": [
"Size.requestDto.message",
"Size.message",
"Size"
],
"arguments": [
{
"codes": [
"requestDto.message",
"message"
],
"arguments": null,
"defaultMessage": "message",
"code": "message"
},
2147483647,
3
],
"defaultMessage": "size must be between 3 and 2147483647",
"objectName": "requestDto",
"field": "message",
"rejectedValue": "a",
"bindingFailure": false,
"code": "Size"
}
],
"message": "Validation failed for object='requestDto'. Error count: 1",
"path": "/"
}
is there any plan to fix this or is this state considered normal?