2
I have a modal where I have two text inputs: CPF
and Senha
. In the input of CPF
have a ng-blur
who makes a Requisition GET
every time I change fields. If I type a CPF
that exists in the bank he made the GET
correctly, but would like to display some warning if you do not find the CPF
in the back-end
.
When I try to fetch 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’t serialize null Objects] with root cause java.lang.Nullpointerexception: You can’t serialize null Objects
How can I treat this error in the best way possible and put an alert on a message or even a red outline on input
of CPF
?
Function that makes the GET
and is passed to the 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:
<div class="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>
Yes, but how do I verify that return?
– DiegoAugusto
You make Ajax calls with certain json return ?
– Eduardo Binotto
Yes, but I’m just not sure how to check this return. I’ve tried using promisse but I don’t think I did it right either.
– DiegoAugusto
Place a Debugger to see what is returning, so it is easy to know how to validate whether it is null or not. If it is returning
undefined
or ""– Eduardo Binotto
I fixed the function by placing promisse. I will edit the question with the new function and the error
– DiegoAugusto
Okay, I’m glad I can help you.
– Eduardo Binotto
I edited the question and put the error that is appearing on the console and modified the function.
– DiegoAugusto
I changed my answer to try to help you with the new problem.
console.log("uhul" +data);
– Eduardo Binotto
Return that:
uhul[object Object]
– DiegoAugusto
But in the browser you can see the content of this object, if you can send to help it.
– Eduardo Binotto
How can I view it, I can only see the result of the GET request
– DiegoAugusto