- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed as not planned
Closed as not planned
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
In terms of DRY (don't repeat yourself), I often feel that Spring adding the StatusCode in front of a HttpStatusCodeException is somehow counter-intuitive. And especially is against DRY, because the statuscode is anyway offered as http status code in the response.
Thus, I want to suggest the following test should succeed:
@Test
public void test() {
   assertEquals("junit", new HttpStatusCodeException(HttpStatusCode.FORBIDDEN, "junit"); //fails, because message = "403 junit"
}
Because as of now, if the HttpStatusCodeException is thrown from a @RestController, Spring renders a message like:
{ 
 ...
 "message": "403 junit"
 ...
}
Source:
HttpStatusCodeException.class:
	private static String getMessage(HttpStatusCode statusCode, String statusText) {
		if (!StringUtils.hasLength(statusText) && statusCode instanceof HttpStatus status) {
			statusText = status.getReasonPhrase();
		}
		return statusCode.value() + " " + statusText; //suggestion: remove the statusCode prefix here
	}
``Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply