Reputation: 2422
In Spring Boot 1.3.5 (Java 8) I'd like my controller to return a custom status code and status msg. By "Custom" I mean, a status code that is not in org.springframework.http.HttpStatus.
I know, I should stick with the standard codes (but I can't).
Currently my controller does a
HttpServletResponse response
.
.
response.setStatus(255)
I get the expected
java.lang.IllegalArgumentException: No matching constant for [255]
at org.springframework.http.HttpStatus.valueOf(HttpStatus.java:488)
at org.springframework.test.web.servlet.result.StatusResultMatchers.getHttpStatusSeries(StatusResultMatchers.java:139)
Note, the operation may be successful, so in that case I want to return a custom 2xx code with a response object (i.e. sendError doesn't help).
Google says this may be available in springframework 4.3, but does anyone have thoughts for implementing now (with springframework 4.2.6)?
Upvotes: 1
Views: 836
Reputation: 393
Custom http codes work on 4.2. This is the matcher in you junit that fails to assert the response code. Should work on your browser.
Upvotes: 2