Last active
June 19, 2017 08:00
-
-
Save luanvuhlu/109ca719c568ec7ef2d59b18d1b95022 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ExceptionHandler(MethodArgumentNotValidException.class) | |
@ResponseBody | |
public ValidationError handleValidationException(MethodArgumentNotValidExceptionexception) { | |
Set<ValidationError> errors = new HashSet<ValidationError>(); | |
for (ObjectError er : exception.getBindingResult().getAllErrors()) { | |
errors.add(new ValidationError(er.getObjectName(), er.getDefaultMessage())); | |
} | |
return new ValidationErrorResponse(errs); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function that Makes Ajax call | |
function doesSomeStuff() { | |
$.ajax({ | |
type: "POST", | |
url: "some/url/in/your/app", | |
// ... etc ... | |
error: function(data) { | |
if (data.errorMessages != null) { | |
handleAjaxError(data); | |
return; | |
} | |
// ... etc ... | |
} | |
}); | |
} | |
// function that handles ajax error | |
function handleAjaxError(data) { | |
var $errorMessageArea = $("#errorMessageArea"); | |
for(var i = 0; i < data.errorMessages.length; i++) { | |
// append the current error message to the element on the web page | |
$errorMessageArea.append($("<li />", { text: data.errorMessages[i] })); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment