Currently for a project I am using api_auth gem. I am hitting on an external api in a function by making a signed request. Currently my code looks like this.
access_id = "someKey"
secret_key = "someRandomGeneratedKey"
request = RestClient::Request.new(url: 'serverUrl', method: get, headers:'headers')
@signed_request = ApiAuth.sign!(access_id, secret_key, request)
@signed_request.execute
I am unable to apply any error handling code to that last statement where I execute the request. Any suggestions?
You have to use begin rescue block to exception handling.
As you should only rescue specific exception, rather than all. So as your code suggest that you are using
rest_client&api-authgem so from documentation you can get list of exception that this gem raise.Example - For
rest_clientbelow exceptions need to be handled. (probably this is the solution of your problem, just replace last line as given below)There are few Exceptions also generated by
api-authgem also likeApiAuth::ApiAuthError,ApiAuth::UnknownHTTPRequestso you need to rescue all this exceptions.Reference link -
http://www.rubydoc.info/gems/api-auth/1.4.0/
Thanks!