We’ll get a 404 because the book’s not found, right?

Twilio’s Lookup is a REST API. Conceptually, you can think of it as an online phonebook with with phone numbers serving as the unique ID. When a phone number is not found, we get a 404.

We can see this as well on the Lookup homepage:

When the Twilio gem encounters a 404, it will throw an exception. Thus, whenever we’re using the Lookup API to validate phone numbers, we need to catch the exception and check to see if the error matches Twilio’s “Not Found” error code: 20404.

To write a function that validates a phone number, we need to: