Home > Back-end >  Validator Exception Spring Integration: returning an error message in validator
Validator Exception Spring Integration: returning an error message in validator

Time:03-24

Does anybody has an idea about how I can return an error message. I am trying to return an specific xml error message in my validator. This is my code:

 @Override
    public void validate(Object target, Errors errors) {
        try {
            ValidationClassUtil.validateDocument(new String((byte[]) target), xmlVersionEnum);
            (//should the error be returned here when I send an invalid xml file over http?)
        } catch (Exception exc) {
            errors.reject(errorCode);
        }
    }

CodePudding user response:

This is not what Validator contract is for. You cannot return from it anything. You can use such a validate() in other wrapper service and then in the end you consult that errors to be able to return whatever you want via its hasErrors() and getAllErrors().

I have showed you some way in this answer: Validator Spring integration

  • Related