Catch exceptions in Ruby

Member

lou_lindgren

by lou_lindgren , in category: Ruby , 2 months ago

Catch exceptions in Ruby 😝

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
begin
    # etc
  rescue Exception => e
    case e
      when LinkedIn::Unauthorized
        account.invalidate_token if !account.invalid_token?
        raise InvalidTokenException.new(account.primary, provider_name)
      when LinkedIn::InformLinkedIn, LinkedIn::Unavailable  #LinkedIn::Unavailable represents 502..503 error codes & LinkedIn::InformLinkedIn represent 500
        raise UnexpectedApiException.new(provider_name)
      else
        handle_api_exception(e, e.message)
    end
  end


Facebook Twitter LinkedIn Telegram Whatsapp Pocket

no answers