Topic: how to return error_code and message_string from method?
I'm trying to write a ruby/rails API for a WebService (WSDL) but I'm stuck with the error handling. I know that in php i once used PEAR (new PEAR_error and and PEAR.is_error() ). I'm sure there is also a nice implementation for something like that in ruby.
so for example in my api class I have a method to login somewhere:
# here I'd like to return an error code and an error string -> error object?
return "session already in use"
response = @service.login(username,password,ip)
if response.status_code == 0
@session = response.message
# return another error object
return "could not login to system"
# everything is fine. we just return the session key
this method would then be called like that:
kt = myapi.new
@return_object = kt.start_session("user", "secret")
if !@return_object # check if something went wrong
logger.info "session established"
how is that done proberly and "ruby" conform?
thanks for your help!