Commit e5a658cf authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

handle empty cat api response

closes #122
parent a1ab3fd1
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -306,9 +306,14 @@ angular.module('cerebro').controller('CatController', ['$scope',
      CatDataService.get(
        api.replace(/ /g, '_'), // transforms thread pool into thread_pool, for example
        function(data) {
          if (data.length) {
            $scope.headers = Object.keys(data[0]);
            $scope.sort($scope.headers[0]);
            $scope.data = data;
          } else {
            $scope.headers = [];
            $scope.data = [];
          }
        },
        function(error) {
          AlertService.error('Error executing request', error);
+8 −3
Original line number Diff line number Diff line
@@ -32,9 +32,14 @@ angular.module('cerebro').controller('CatController', ['$scope',
      CatDataService.get(
        api.replace(/ /g, '_'), // transforms thread pool into thread_pool, for example
        function(data) {
          if (data.length) {
            $scope.headers = Object.keys(data[0]);
            $scope.sort($scope.headers[0]);
            $scope.data = data;
          } else {
            $scope.headers = [];
            $scope.data = [];
          }
        },
        function(error) {
          AlertService.error('Error executing request', error);
+11 −0
Original line number Diff line number Diff line
@@ -73,6 +73,17 @@ describe('CatController', function() {
        jasmine.any(Function)
      );
    });
    it('cleans up in case of empty response', function() {
      this.scope.headers = [1, 2, 3];
      this.scope.data = [1, 2, 3];
      this.CatDataService.get = function(api, success, error) {
        success([]);
      };
      spyOn(this.CatDataService, 'get').andCallThrough();
      this.scope.get('foo');
      expect(this.scope.headers).toEqual([]);
      expect(this.scope.data).toEqual([]);
    });
    it('alerts in case of failure', function() {
      this.CatDataService.get = function(api, success, error) {
        error('failed!');