3

I am new to Ruby/ Ruby on Rails. I wrote the below code to get a boolean value from api. The API call failed and it went to the rescue block. But for some reason, it set the value to true. I don't understand how that happened.

@is_attached = OnDeck.api.check_is_attached(@decision.application_number, current_user)

Api call / client wrapper Code

def check_is_attached(app_number, user)
   begin
        client.check_is_attached(app_number, user.auth_token)
   rescue OnDeckException::MerchantApiException => e
        Rails.logger.error("Caught exception #{e} while calling check_mbs_attached for app_number : #{app_number}")
 end
end

2 Answers 2

6

The rails logger returns true on successfully logging:

[2] pry(main)> Rails.logger.error("Caught exception")
Caught exception
=> true

Because that is the last line executed in the method, that value is returned as ruby has implicit return.

Sign up to request clarification or add additional context in comments.

1 Comment

Correct and you can still return whatever you wish from a rescue block.
1
Rails.logger.error(string)

returns true as can be seen:

2.3.1 :002 > Rails.logger.error('foo')
foo
 => true 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.