Posted by nicholasThompson on November 9, 2009 at 12:23am
Jump to:
| Project: | Services |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (works as designed) |
Issue Summary
I have noticed that if there is no authentication system setup, the default action for services_auth_invoke is to return TRUE.
this makes logical sense if other functions calling this expect a more "is this allowed? TRUE/FALSE" kind of setup (such as user_access()) - however in this case it appears that the result is expected to be an array of a service failure error if there authentication is a problem. Returning TRUE confuses things as you end up with "#data => 1, #error => 1"...
Setting the default return to NULL seems to fix this... Is this intentional or have I missed something?
Comments
#1
Hmm, I think that this is a heritage from the way key auth worked before the pluggable auth patch (I think, have not double-checked). When I wrote the patch my focus was to cause as little disruption as possible, therefore things like that stuck. In your example the response is probably returned because if something really goes wrong in a auth module it will return a description of what the failure was, so it would become: "#data => 'Who are you really?' #error => 1". Not double-checking here, please correct me if I'm wrong.
I would say that using return values for error handling is pretty bad overall. The servers are actually free to do whatever they want when services_error is called. For instance in rest_server I've chosen to throw an exception instead of relying on return values. As the server is the one that calls services_method_call it also has the opportunity to catch any exceptions. I'm actually thinking about making Exceptions the default way to tell services that something has gone terribly wrong, but that's definitely a 3.x thing.
I'm marking this as a by design, but I agree with you that the design may not be all that good. Feel free to change it back if you disagree.