diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index d836883cab2b22c00ea77a422e71364d49d28cee..94e7588e4e380d7d59e03b6ba91357d14a6e143b 100644 --- a/lib/tel_selections.rb +++ b/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)