I have a modal where I have two inputs of type text: CPF
and Senha
. In the input of CPF
I have a ng-blur
that makes a Request GET
every time I change the field. If I type a CPF
that exists in the database, it made GET
correctly, but I would like to display some alert if I do not find CPF
in back-end
.
When I try to find a CPF that does not exist, this is the error that happens on the server:
GRAVE: Servlet.service () for servlet [default] in context with path [/ UnimedWS] threw exception [java.lang.NullPointerException: You can not serialize null objects] with root cause java.lang.NullPointerException: You can not serialize null objects
How can I treat this error as best I can and put an alert in a message or even a red outline in input
of CPF
?
Function that makes GET
e is passed to ng-blur
:
$scope.getBeneficiario = function(usuario){
loginAPI.getBeneficiario(usuario.cpf).success(function(data){
console.log("uhul" +data);
return loginAPI.getBeneficiario(usuario.cpf);
})
.error(function(response, status) {
console.log("Resposta: "+response +"Status: "+status);
});
};
Page:
<divclass="alinhar">
<form name="usuarioForm">
<input class="form-control" type="text" name="nome" placeholder="CPF" ng-model="usuario.cpf" ng-required="true" ng-blur="getBeneficiario(usuario)" />
<input class="form-control" type="text" name="fone" placeholder="Senha" ng-model="usuario.senha"
ng-required="true"/>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary btn-block" ng-click="adicionarUsuario(usuario)" ng-disabled="usuarioForm.$invalid">Salvar</button>
</div>