Provide response context in case of API error
cyb- opened this issue ยท 7 comments
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.
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.
@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! ๐