javascript - NodeJS + AngularJS - after some time, I get net::ERR_CONNECTION_RESET -
i'm using express nodejs , angularjs in front-end. after click here, add data there, update record here, show list there, net::err_connection_reset
. it's strange, after 8 or 9 navigations through application, got error. before this, ajax calls doing fine.
an example of angularjs controller:
app.controller('grupocontroller', ['$scope', '$location', '$routeparams', 'gruposervice', function ($scope, $location, $routeparams, gruposervice) { $scope.carregardependenciasmeusgrupos = function () { gruposervice.carregardependenciasmeusgrupos().then(function (result) { $scope.data = { grupos: result.data }; }); }; $scope.editargrupo = function(grupo) { $location.path('/editar-grupo/' + grupo.id); }; }]);
and example of http call:
function ajax(url, async, method, params, isjson, showloading) { var deferred = $q.defer(); $http.post('http://localhost:3000' + url, params).success(function(result) { if (result.statuscode === 403) { $location.path('/login'); } else { if (result.success) { deferred.resolve(result); } else { deferred.reject(); if (result.errormessage) { alert(result.errormessage); } if (result.redirectto) { window.location.href = result.redirectto; } } } }).error(function(err) { deferred.reject(); }); return deferred.promise; }
this approach i'm using express , nodejs create action called through ajax method above:
app.post('/grupos/get-dependencies-to-grupos', app.ensureauthentication, function(request, response, next) { query.openconnection().then(function(connection) { var gruposrepository = new repositories.grupos(connection); gruposrepository.getdependenciastogrupos( request.headers["authorization"], request.body.grupoid) .then(function(result) { response.json({ statuscode: 200, data: result }); }, function(getdependencieserror) { response.json({ statuscode: 500, errormessage: getdependencieserror }); }); }); });
after 8 or 9 navigations, app stopped work suddenly. can guys me? thank you!
what happens if "getdependenciastogrupos" promise result error, don't have "catch".
so if in error, there no http response server (nodejs), , browser, after waiting responses few requests, shuts down connexion.
try add catch handler promise :
gruposrepository.getdependenciastogrupos( request.headers["authorization"], request.body.grupoid) .then(function(result) { response.json({ statuscode: 200, data: result }) .catch(function(error){response.json({ statuscode: 503, data: error})});
Comments
Post a Comment