lib/parliament/utils/helpers/postcode_helper.rb in parliament-utils-0.11.1 vs lib/parliament/utils/helpers/postcode_helper.rb in parliament-utils-0.11.2

- old
+ new

@@ -17,13 +17,13 @@ postcode = clean_input(raw_input) begin Parliament::Utils::Helpers::ParliamentHelper.parliament_request.constituency_lookup_by_postcode.get(params: { postcode: postcode }) rescue Parliament::ClientError - raise(PostcodeError, I18n.t('error.no_constituency').capitalize) + raise(PostcodeError, I18n.t('error.postcode_invalid_html')) rescue Parliament::ServerError - raise(PostcodeError, I18n.t('error.lookup_unavailable').capitalize) + raise(PostcodeError, I18n.t('error.lookup_unavailable')) end end # Replaces whitespace with a hyphen. # @param [String] postcode the string to be hyphenated. @@ -55,10 +55,10 @@ # We decided to use a loose regex - this matches the different postcode formats, but doesn't validate against invalid letters and numbers, only their positions. def self.clean_input(raw_input) postcode = raw_input.gsub(/\s+/, '').upcase - postcode.match(/[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/).nil? ? raise(PostcodeError, I18n.t('error.postcode_invalid').capitalize) : postcode + postcode.match(/[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}/).nil? ? raise(PostcodeError, I18n.t('error.postcode_invalid_html')) : postcode end class PostcodeError < StandardError def initialize(message) super(message)