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

Custom web input exceptions in WebFlux [SPR-17232] #21765

Closed
spring-projects-issues opened this issue Aug 31, 2018 · 2 comments
Closed

Custom web input exceptions in WebFlux [SPR-17232] #21765

spring-projects-issues opened this issue Aug 31, 2018 · 2 comments
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 31, 2018

Enzo Bonggio opened SPR-17232 and commented

  1. Having a PostMapping like this
@PostMapping("/body") public Mono<Void> body(@Valid @RequestBody BodyClass bodyClass) { return Mono.empty().then(); }

 

  1. When we send a request with a null body
@Autowired
private TestRestTemplate restTemplate 
def "test post body null"() {
    given:
    def bodyClass = null
    def headers = new HttpHeaders()
    headers.setContentType(MediaType.APPLICATION_JSON);
    def request = new HttpEntity<MultiValueMap<String, String>>(bodyClass, headers);
    when:
    def response = restTemplate.postForEntity("/body", request, ErrorResponse.class)
    then:
    assert response.statusCode == HttpStatus.BAD_REQUEST
}

 

  1. We need to handle ServerWebInputException that is thrown from AbstractMessageReaderArgumentResolver 
private ServerWebInputException handleMissingBody(MethodParameter param) {
     return new ServerWebInputException("Request body is missing: " + param.getExecutable().toGenericString());
}

 

Right now there is no way to override method that is thrown from AbstractMessageReaderArgumentResolver 

At least we should send MethodParameter in the constructor of ServerWebInputException or tell a way to override that implementation   


Affects: 5.0.8

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 31, 2018

Enzo Bonggio commented

I have another case where this happen:

 

When you are missing a header we have the same issue on RequestHeaderMethodArgumentResolver

@Override
protected void handleMissingValue(String name, MethodParameter parameter) {
 String type = parameter.getNestedParameterType().getSimpleName();
 throw new ServerWebInputException("Missing request header '" + name +
 "' for method parameter of type " + type);
}

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 21, 2018

Rossen Stoyanchev commented

Yes, indeed we should be using the constructor with a MethodParameter in places where it is available. 

@spring-projects-issues spring-projects-issues added type: enhancement in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.1.3 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants