var TestErrors = TestErrors || {}

TestErrors.UPDATE_INTERVAL = 2*1000;

TestErrors.storage = [];

TestErrors.updateTestErrors = _.throttle(function($http) {
	$http.get('/controller/errors?start=' + TestErrors.storage.length).then(function(data) {
		TestErrors.storage = TestErrors.storage.concat(data.data);
	});
}, TestErrors.UPDATE_INTERVAL);

TestErrors.getTestErrors = function() {
	return TestErrors.storage;
}

TestErrors.clearAll = function() {
	TestErrors.storage = [];
}

otsApp.factory('testErrors', ['$http', function ($http) {	
	var testErrors = function() {
		TestErrors.updateTestErrors($http);
		return TestErrors.getTestErrors();	
	}
	
	testErrors.clearAll = TestErrors.clearAll;
	
	return testErrors;
}]);
