handle bindexception
This commit is contained in:
parent
3a6163c555
commit
ae5d1dde09
|
@ -83,9 +83,19 @@ function register(){
|
|||
{
|
||||
window.location.href = "<c:url value="/emailError.html"></c:url>";
|
||||
}
|
||||
else{
|
||||
else if(data.responseJSON.error.indexOf("InternalError") > -1){
|
||||
window.location.href = "<c:url value="/login.html"></c:url>" + "?message=" + data.responseJSON.message;
|
||||
}
|
||||
else{
|
||||
var errors = $.parseJSON(data.responseJSON.message);
|
||||
$.each( errors, function( index,item ){
|
||||
$("#"+item.field+"Error").show().html(item.defaultMessage);
|
||||
});
|
||||
errors = $.parseJSON(data.responseJSON.error);
|
||||
$.each( errors, function( index,item ){
|
||||
$("#globalError").show().append(item.defaultMessage+"<br>");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.http.HttpHeaders;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mail.MailAuthenticationException;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
|
@ -27,6 +28,14 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
|
|||
// API
|
||||
|
||||
// 400
|
||||
@Override
|
||||
protected ResponseEntity<Object> handleBindException(BindException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
|
||||
logger.error("400 Status Code", ex);
|
||||
final BindingResult result = ex.getBindingResult();
|
||||
final GenericResponse bodyOfResponse = new GenericResponse(result.getFieldErrors(), result.getGlobalErrors());
|
||||
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseEntity<Object> handleMethodArgumentNotValid(final MethodArgumentNotValidException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
|
||||
logger.error("400 Status Code", ex);
|
||||
|
@ -48,14 +57,14 @@ public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionH
|
|||
public ResponseEntity<Object> handleMail(final RuntimeException ex, final WebRequest request) {
|
||||
logger.error("500 Status Code", ex);
|
||||
final GenericResponse bodyOfResponse = new GenericResponse(messages.getMessage("message.email.config.error", null, request.getLocale()), "MailError");
|
||||
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
|
||||
return new ResponseEntity<Object>(bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@ExceptionHandler({ Exception.class })
|
||||
public ResponseEntity<Object> handleInternal(final RuntimeException ex, final WebRequest request) {
|
||||
logger.error("500 Status Code", ex);
|
||||
final GenericResponse bodyOfResponse = new GenericResponse(messages.getMessage("message.error", null, request.getLocale()), "InternalError");
|
||||
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
|
||||
return new ResponseEntity<Object>(bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -84,9 +84,19 @@ function register(){
|
|||
{
|
||||
window.location.href = "<c:url value="/emailError.html"></c:url>";
|
||||
}
|
||||
else{
|
||||
else if(data.responseJSON.error.indexOf("InternalError") > -1){
|
||||
window.location.href = "<c:url value="/login.html"></c:url>" + "?message=" + data.responseJSON.message;
|
||||
}
|
||||
else{
|
||||
var errors = $.parseJSON(data.responseJSON.message);
|
||||
$.each( errors, function( index,item ){
|
||||
$("#"+item.field+"Error").show().html(item.defaultMessage);
|
||||
});
|
||||
errors = $.parseJSON(data.responseJSON.error);
|
||||
$.each( errors, function( index,item ){
|
||||
$("#globalError").show().append(item.defaultMessage+"<br>");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue