5

I have an issue displaying an error message at the moment that a bad request is triggered.

@DeleteMapping("/{projectId}/bugs/{bugId}")
public void deleteBug(@PathVariable (value = "projectId") Long projectId,
                      @PathVariable (value = "bugId") Long bugId){
    if (!projectService.existById(projectId) || !bugService.existById(bugId)) {
        throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "ProjectId " + projectId + " or BugId " + bugId + " not found");
    }
    bugService.deleteBug(bugId);
}

This is the JSON response when I trigger the Response:

{
"timestamp": "2020-05-29T15:40:41.302+00:00",
"status": 400,
"error": "Bad Request",
"message": "",
"path": "/projects/3/bugs/2"  }

As you can see the message is not appearing. If I change the HttpStatus in the code it actually works but for some reason, the message is not working.

I checked the constructor of the class and it actually allows only the status and the reason.

Am I missing something or is it a bug in the ResponseStatusException class?

3
  • Please check here stackoverflow.com/questions/61659000/… Commented May 29, 2020 at 15:50
  • 1
    Which spring-boot version do you use? You may use older versions such as 2.2.6.RELEASE. I have the same problem with version 2.3.0.RELEASE, which is the newest by the time of this comment. Everything is good with the previous ones. Commented Jun 3, 2020 at 9:51
  • @AchmadYogiPrakoso thank you a lot for your comment. I will give it a try because you are right, I'm using the newest spring boot version Commented Jun 3, 2020 at 16:51

1 Answer 1

9

I also encountered this. It's not a bug, so downgrading is not the best resolution. The Spring Boot 2.3.0 release notes explain:

Changes to the Default Error Page's Content

The error message and any binding errors are no longer included in the default error page by default. This reduces the risk of leaking information to a client. server.error.include-message and server.error.include-binding-errors can be used to control the inclusion of the message and binding errors respectively. Supported values are always, on-param, and never.

So for example, in your application configuration you can set these to show message but not trace output (YAML example):

server:
  error:
    include-message: ALWAYS
    include-stacktrace: NEVER
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.