java - Support handler exception -
i have controller
@putmapping(value = "/changeemail", consumes = mediatype.application_json_value) public httpentity<changeemaildto> showchangeemail( @requestbody @valid changeemaildto changeemaildto ) { system.out.println("email: " + changeemaildto.getemail()); return responseentity.ok(changeemaildto); }
throws exception when validation fails methodargumentnotvalidexception. created exception service
@exceptionhandler(methodargumentnotvalidexception.class) @responsestatus(httpstatus.bad_request) @responsebody public validationerrordto processvalidationerror(methodargumentnotvalidexception ex) { bindingresult result = ex.getbindingresult(); list<fielderror> fielderrors = result.getfielderrors(); return processfielderrors(fielderrors); }
still throwing me exception in console
org.springframework.web.bind.methodargumentnotvalidexception: validation failed argument @ index 0 in method: public org.springframework.http.httpentity<com.movie.database.app.dto.changeemaildto> com.movie.database.app.rest.controller.usercontroller.showchangeemail(com.movie.database.app.dto.changeemaildto), 2 error(s): [field error in object 'changeemaildto' on field 'email': rejected value []; codes [isvalidemail.changeemaildto.email,isvalidemail.email,isvalidemail.java.lang.string,isvalidemail]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [changeemaildto.email,email]; arguments []; default message [email]]; default message [please enter valid e-mail address.]] [field error in object 'changeemaildto' on field 'email': rejected value []; codes [notempty.changeemaildto.email,notempty.email,notempty.java.lang.string,notempty]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [changeemaildto.email,email]; arguments []; default message [email]]; default message [may not empty]]
why throw exception in console if created service?
Comments
Post a Comment