Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 189 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"message" field is empty in error response Spring Boot

#1
I have handled unauthorized exception like this

@ResponseStatus(value= HttpStatus.UNAUTHORIZED)
public class UnauthorizedException extends RuntimeException {
public UnauthorizedException(String message) {
super(message);
}
}

but when I throw the error as follows

throw new UnauthorizedException("Invalid credentials");

I get the error message empty in the response as follows

{
"timestamp": "2020-05-27T13:44:58.032+00:00",
"status": 401,
"error": "Unauthorized",
"message": "",
"path": "/auth/register"
}

I tried using,

throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid credentials");
but the result is still the same. When I added *spring-boot-devtools* dependency, I get the message as expected with the stack trace as well. How can I fix this?

Spring version : 2.3.0
Java Version: 11.0
Reply

#2
Ok got it, they have changed the default value for server.error.include-message to "never" (see the comment section here: [Spring 2.3.0 Release Info][1]

All the default values are listed here:
[Spring Boot Reference Documentation][2]

Just configure your application.yaml (or properties) like this.

server:
error:
include-message: always
include-binding-errors: always

Mind that showing error messages may leak information about your server implementation.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through