twilio / twilio-ruby

A Ruby gem for communicating with the Twilio API and generating TwiML
MIT License
1.35k stars 462 forks source link

Question: Verify API error handling #617

Closed twe4ked closed 2 years ago

twe4ked commented 2 years ago

Issue Summary

We're currently upgrading from the Authy gem. We're using two APIs, verifications.create and verification_checks.create. I'm wondering what I need to check on the result object that those endpoints return.

In this migration example the code is checking the status of the response:

if verification_check.status == "approved"

But in all my testing, the client will raise an exception. Details below.

Do I need to check the status of either of these calls? And if so, how do I create API requests that will exercise this path?

Steps to Reproduce

For the verifications API:

client
  .verify
  .v2
  .services("SNIP")
  .verifications
  .create(to: "+61400000000", channel: "sms")

From my testing, all “failure” cases will raise a Twilio::REST::RestError error, for instance an invalid phone number. Given that I'm assuming I don't need to check the result at all and if I don't see an exception I can assume the API call was successful.

For the verification_checks API:

client
  .verify
  .v2
  .services("SNIP")
  .verification_checks
  .create(to: "+61400000000", code: "SNIP")

As above, with my test example being an invalid code.

Technical details:

twe4ked commented 2 years ago

A bit more digging and a bit more reading of the documentation and I've worked this out.

From the docs:

The status of the verification. Can be: pending, approved, or canceled.

So this is the status of the actual “verification check” not the result of the check. I got a bit thrown by the API returning errors for things like invalid codes.