Skip to content

Failed requests should throw an error, not just return it #69

Closed
@kentcdodds

Description

@kentcdodds

On this line in findAll, when the request fails (404 for example) angular-data is returning the error. This causes a resolve in a route to resolve to the error. Because of this when I do this, my injected users is the err object that angular-data is returning (not great...)

// ... some state definitions

$stateProvider.state('root.auth.home.locks.list', {
  url: '',
  templateUrl: homeTemplateRoot + 'Locks/LocksCtrl.html',
  controller: 'LocksCtrl',
  resolve: {
    locks: resolveDS('findAll', ['lock', {}]),
    users: resolveDS('findAll', ['user', {}])
  }
});

// ... other state definitions

function resolveDS(method, args) {
  if (!_.isArray(args)) {
    args = [args];
  }
  return function(DS) {
    return DS[method].apply(DS, args);
  };
}

// in my LocksCtrl
angular.module('pk.web').controller('LocksCtrl', function ($scope, locks, users, _) {
  // some $scope initialization stuff using the injected users.
  // however, if the request to findAll users fails, the users object is actually the error returned by angular-data. I would rather the controller not even initialized if this happens.
});

Let me know if I need to be more clear on what is actually happening. But I'm pretty sure all that needs to happen is on that line we need to change the "return" to "throw"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions