Don't swallow all errors

Stephen Paul Weber created

Just the ones we meant to report to the user

Change summary

lib/tel_selections.rb | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

Detailed changes

lib/tel_selections.rb 🔗

@@ -52,6 +52,8 @@ class TelSelections
 	end
 
 	class ChooseTel
+		class Fail < RuntimeError; end
+
 		def initialize(db: DB, memcache: MEMCACHE)
 			@db = db
 			@memcache = memcache
@@ -66,13 +68,13 @@ class TelSelections
 				next available if available.is_a?(String)
 
 				choose_from_list(available.tns)
-			rescue StandardError
+			rescue Fail
 				choose_tel(error: $!.to_s)
 			end
 		end
 
 		def choose_from_list(tns)
-			raise "No numbers found, try another search." if tns.empty?
+			raise Fail, "No numbers found, try another search." if tns.empty?
 
 			Command.reply { |reply|
 				reply.allowed_actions = [:next, :prev]
@@ -140,6 +142,8 @@ class TelSelections
 				BandwidthIris::AvailableNumber
 					.list(@iris_query)
 					.map { |tn| Tn::Bandwidth.new(Tn::Option.new(**tn)) }
+			rescue BandwidthIris::APIError
+				raise Fail, $!.message
 			end
 
 			def fetch_local_inventory
@@ -334,7 +338,7 @@ class TelSelections
 					return block.call($1 || $&, *$~.to_a[2..-1], **kwa) if match_data
 				end
 
-				raise "Format not recognized: #{q}"
+				raise Fail, "Format not recognized: #{q}"
 			end
 
 			def self.replace_region_names(query)