Vonage/vonage-ruby-sdk

Provide response context in case of API error

cyb- opened this issue ยท 7 comments

cyb- commented

Hello ๐Ÿ™‚

In my compagny, we're trying to upgrade to the latest 7.4.0 but we are facing an issue since the SDK is raising a generic Vonage::Error exception in case of API error, without providing any response context, except for the message.

On our side, in case of API error (status != 0), we need to look at the response status to handle it correctly.

For example, with the number_insight API, we're sometimes receiving a 44 status, which we are handling differently from the other errors

response = client.number_insight.standard(params)

case response.status
when '0'
  handle_success(response)
when '44'
  handle_lookup_handler_error(response)
else
  handle_error(response)
end

Since the 7.0.0 release, we're not able to do it anymore

We're also facing this kind of issue with the sms and the verify API

It could be useful to be able to access the api response object from the raised error to be able to do something like

begin
  response = client.number_insight.standard(params)
  handle_success(response)
rescue Vonage::Error => e
  case e.response.status
  when '44'
    handle_lookup_handler_error(e.response)
  else
    handle_error(e.response)
  end
end

I can spend a bit of time on it, but I'd like to have your opinion before doing anything

I'd love the feature that exposes response status too.

We're facing the same situation described by @cyb- . We wrote code to switch our logic by an error text as a workaround but it's so unstable that I hope to stop it and to want to handle with a proper code.

Hi @cyb- and @ohbarye My apologies for the delay as we understand this may have impacted your work. I'm currently looking into it. Seems like you're using a workaround at the moment? I'll keep you updated on the progress. If you need anything else in the meantime, please feel to reach out.

Hello @geekchick
Is there any progress for this?

Seems like you're using a workaround at the moment?

Yes. I'm using a workaround that handles errors with an error text like below even though I know it is quite fragile and unstable.

begin
  cliend.verify.request(params)
rescue => e # This is Vonage::Error class
  if e.message.end_with?('does not exist or its no longer active.')
    do_error_handling_for_this_error
  elsif e.message.end_with?("can't be cancelled within the first 30 seconds.")
    do_error_handling_for_another_error
  elsif ...
    ...
  end
end

I'm surethe error handling by gem users could be better as described in #197 (comment), if Vonage::Error would provide response context.

@cyb- and @ohbarye apologies for the lack of activity on this feature request. I'm going to be actively exploring implementing this over the next few weeks. Will keep you updated.

cyb- commented

@superchilled thanks for your response, nice to read that ๐Ÿ™‚

BTW,I think I did a mistake on the repo where I created a PR about that (sorry ๐Ÿ™ˆ), but for instance, that's our "workaround" #204 ๐Ÿ˜

@cyb- Version 7.5.0 is published! ๐Ÿ™‚