I am a bit new to web programming..so. I am writing user register for an app. On server side I use Java, Tomcat and servlet, and on the client side jQuery. I want to check if the user I am registering exist and if so, I want to response with the text of my thrown exception. I've written the request like:
"$.ajax({
url: url,
method: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(regUser),
success: function(response) {
localStorage.setItem(LOCAL_STORAGE_AUTHKEY_KEY, response.authKey);
localStorage.setItem(LOCAL_STORAGE_USERNAME_KEY, response.username);
resolve(response);
},
error: function(error) {
console.log(error);
toastr.error(error);
}
});"
and the response, when I enter repeating user like:
catch (Exception e) {
String errorMessage = e.getMessage();
System.out.println(errorMessage);
response.setStatus(400);
response.getWriter().write(errorMessage);