lundi 5 juin 2017

Should I return an Exception? - Ruby

I have a service class called IgUserProfile which looks something like this:

class IgUserProfile < IgRequest
  def self.call(user_name)
    json = make_request(user_name)
    user_info = json['user_info'].text
    Parsers::UserProfile.new user_info
  end
end

Sometimes, if the user does not exist (json comes empty), an error is raised when calling .text. We can handle that error and we know what it means: 'the user was not found'.

However, I'm trying to think of what would be the best result to return from IgUserProfile.call in this case. I was thinking of returning an Exception. Something as IG::UserNotFound. However, as I see, Exceptions indicate errors, but I'm not sure this is an error from our application standpoint. How can I approach this?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire