# frozen_string_literal: true module GetYourRep # Custom Error handling classes and methods. module Errors # Errors for invalid or inadequate addresses. class AddressError < ArgumentError # Raise when the address is not a string or an integer. # Supports integers for zip codes. def invalid_address_type 'Entry must be of types String or Integer' end # Raise when a rep cannot be found with the given parameters. def reps_not_found "Error message received. Some reps were not found. Confirm your address and check your parameters. \ Try a full address if you used a zip." end end # Errors raised when type-specific operations are performed invalidly. # These operations will generally be association-building operations. class GetYourRepTypeError < TypeError def not_a_rep # :nodoc: 'Object must be a Representative.' end def not_an_office # :nodoc: 'Object must be an OfficeLocation.' end def not_a_delegation # :nodoc: 'Object must be a Delegation.' end end # Error raised when CLI command is invalid. class CommandNotFoundError < NoMethodError def command_not_found # :nodoc: "Command not found. Use 'help' command for a list of possible commands." end end def not_an_office_error # :nodoc: raise GetYourRepTypeError rescue GetYourRepTypeError => error puts error.not_an_office end def not_a_del_error # :nodoc: raise GetYourRepTypeError rescue GetYourRepTypeError => error puts error.not_a_delegation end def not_a_rep_error # :nodoc: raise GetYourRepTypeError rescue GetYourRepTypeError => error puts error.not_a_rep end def address_type_error # :nodoc: raise AddressError rescue AddressError => error puts error.invalid_address_type.bold.red end def command_not_found_error # :nodoc: raise CommandNotFoundError rescue CommandNotFoundError => error puts error.command_not_found.bold.red end def reps_not_found_error # :nodoc: raise AddressError rescue AddressError => error puts error.reps_not_found.bold.red end end end