Possibly unhandled rejection:

0

Hi, I'm having this problem when I try to make an http.post request in a restfull api.

  

Possibly unhandled rejection: {"timestamp": 1517450563066, "status": 400, "error": "Bad Request", "exception": "org.springframework.web.bind.MethodArgumentNotValidException", "errors": [{"codes": ["NotNull.products.price_product", "NotNull.price_product", "NotNull.java.lang.Double", "NotNull"], "arguments": [{"codes": null, "defaultMessage": "price_product", "code": "price_product"}], "defaultMessage": "can not be null", "objectName" : "products", "field": "price_product", "rejectedValue": null, "bindingFailure": false, "code": "NotNull"}, {"codes": ["NotNull.products.name_product" , "arguments": null, "defaultMessage", "arguments": "[name] : "name_product", "code": "name_product"}], "defaultMessage": "can not be null", "objectName": "products", "field": "name_product", "rejectedValue": null, "bindingFailure ": false," code ":" NotNull "}]," message ":" Validation failed for object = 'products'. Error count: 2 "," path ":" / product "}," status ": 400," config ": {" method ":" POST "," transformRequest ": [null]," transformResponse ": [null] , "jsonpCallbackParam": "callback", "url": " link ", "data": {"name": "saba", "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" -Type ":" application / json; charset = utf-8 "}}," statusText ":" "}   (anonymous) @ angular.js: 14324   (anonymous) @ angular.js: 10834   g @ angular.js: 16668   $ eval @ angular.js: 17958   $ digest @ angular.js: 17772   $ apply @ angular.js: 18066   l @ angular.js: 12207   N.onload @ angular.js: 12361   XMLHttpRequest.send (async)   (anonymous) @ angular.js: 12407   p @ angular.js: 12152   (anonymous) @ angular.js: 11905   (anonymous) @ angular.js: 16643   $ eval @ angular.js: 17958   $ digest @ angular.js: 17772   $ apply @ angular.js: 18066   (anonymous) @ angular.js: 26678   dispatch @ jquery-3.1.1.min.js: 3   q.handle @ jquery-3.1.1.min.js: 3

I've never had problems with this type of get request. here is my code.

var app =   angular.module("app").controller("ProdutosController", function($scope, ProdutosFactory){

$scope.addprodutos = function(){
    ProdutosFactory.addprodutos($scope.prod);


}

}) .factory ("ProductsFactory", ['$ http', function ($ http) {     var fac = {};

    fac.addprodutos = function(prod){
        $http.post("http://localhost:9000/product", prod).then(function(response){

            alert(response.status);
        })
    }
return fac;

}])

html code:

<div ng-controller="ProdutosController">


<form name="addprodutosform" ng-submit="addprodutos()">
    <table>
        <tr>
            <td>Nome do Produto</td>
            <td><input type="text" ng-model="prod.name"/></td>
        </tr>
        <tr>
            <td>Preco</td>
            <td><input type="text" ng-model="prod.price"/></td>
        </tr>
        <td colspan="2"><input type="submit" value="submit"/></td>
    </table>

</form>

I do not know what to do, but I do not know what to do.

    

asked by anonymous 01.02.2018 / 03:11

0 answers