V
V
Vanya Petilo2019-11-06 16:39:46
Spring
Vanya Petilo, 2019-11-06 16:39:46

How to pass error message in http request?

Hey!
I have an exception I created:

@ResponseStatus(HttpStatus.CONFLICT)
public class UserAlreadyExistException extends RuntimeException{

    public UserAlreadyExistException(String message) {
        super(message);
    }
}

But when I throw it inside the request:
if (userService.findByEmail(email) != null) {
    throw new UserAlreadyExistException("User with this email already exist!");
}

The message doesn't appear to be saved, because it's null inside response:
MockHttpServletResponse:
           Status = 409
    Error message = null

Tell me how to fix it? Or, how can I better pass the exception along with the message? This is important because The response of the client depends on the content of the message.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2019-11-06
@mr_garther

Vanya Petilo use
https : //docs.spring.io/spring/docs/5.0.1.RELEASE/j...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question