08-02-2023, 04:29 PM
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
@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