Every so often with Remoting I experience awkward situations where I need to return either true or some sort of error other than false. An example awkward sitatution is a registration method.
The method requires an email and password. There are 4 “falt” situations that come to mind right away. (1) Empty email address. (2) Empty password. (3) Email is not valid format. (4) The email is not unique. The “awkward” part is that even when returning anything other than true, the result still comes back to the onResult method. I’ve seen other people’s logic return an object with some special keys set. For EX: {error:true, message:’some message’}. But that is still awkward because they were testing for that object in every onResult method. See what the problem is? There needs to be an error state in Flash but the onResult method is always called.
A solution in RubyAMF is the new FaultObject helper. In services/rubyamf/helpers/fault_object. Returning this object from a service method call results in a behind the scenes switcheroo that returns a valid Fault object to the player. It works with AMF0 / AMF3 / RemoteObject.
Here is a simple RubyAMF example:
require RUBYAMF_HELPERS + 'fault_object'
class MyService
def register(email, password)
if(!email)
return FaultObject.new("EMAIL_EMPTY", "Email can not be empty.")
end
end
end
Now let’s assume MyService#register is attempted from Flash with an empty email. The result is a correct mapping to the onFault handler with code / faultCode and description / faultString set. Simple!
This new feature will be in the next release (0.9.2). It’s in SVN right now.
What about you AMFPHP folks? If you use SSR:Super Simple Remoting the package has a built in forward to onFault when the keys “faultCode” and “faultString” are present in whatever the result is. For ex, if you return this:
return $o = array( "faultString" => "some Message", "faultCode" => "someCode" );
The result get’s forwarded to your onFault handler instead. Sweet!


