Because the EntityAPI returns false when we do not have an entity to pass to it, we return a 401. I think it would be better to follow the node resource paradigm of returning an empty 200 OK for a non-existant entity. Patch attached returns TRUE when $entity_type = 'user', $entity is empty and $op = view.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jpstrikesback’s picture

Title: Return empty 200 when requested user doesn't exist » UUID Services should return HTTP 200 when requested user doesn't exist

Any thoughts on this?

skwashd’s picture

Status: Needs review » Needs work

If a user doesn't exist we should return 404 (not found) as the entity doesn't exist. 200 suggests everything is OK, which it isn't. 401 doesn't make sense either.

btw how does the stock services module handle this?

jpstrikesback’s picture

Issue summary: View changes

Hey @skywashd apologies for the rather long delay in replying :P

Here is what services does in _user_resource_access():

  // Check if the user exists if appropriate.
  if ($op != 'create' && $op != 'register' ) {
    $account = user_load($args[0]);
    if (!$account) {
      return services_error(t('There is no user with ID @uid.', array('@uid' => $args[0])), 406);
    }
  }
skwashd’s picture

Status: Needs work » Needs review
FileSize
1.18 KB

Attached is a patch that returns a 406.

skwashd’s picture

Status: Needs review » Fixed

The passed this, so it is in.

  • skwashd committed cb88f35 on 7.x-1.x
    Isssue #1959276 by jpstrikesback, skwashd: Return 406 if user doesn't...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.