diff --git i/src/phonenumberutil.js w/src/phonenumberutil.js index 7569eee..2b20e4a 100644 --- i/src/phonenumberutil.js +++ w/src/phonenumberutil.js @@ -2972,7 +2972,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.getCountryCodeForRegion = * calling code for. * @return {number} the country calling code for the region denoted by * regionCode. - * @throws {Error} if the region is invalid + * @throws {string} if the region is invalid * @private */ i18n.phonenumbers.PhoneNumberUtil.prototype.getCountryCodeForValidRegion_ = @@ -2981,7 +2981,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.getCountryCodeForValidRegion_ = /** @type {i18n.phonenumbers.PhoneMetadata} */ var metadata = this.getMetadataForRegion(regionCode); if (metadata == null) { - throw new Error('Invalid region code: ' + regionCode); + throw 'Invalid region code: ' + regionCode; } return metadata.getCountryCodeOrDefault(); }; @@ -3379,7 +3379,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.maybeExtractCountryCode = i18n.phonenumbers.PhoneNumber.CountryCodeSource.FROM_DEFAULT_COUNTRY) { if (fullNumber.getLength() <= i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) { - throw new Error(i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD); + throw i18n.phonenumbers.Error.TOO_SHORT_AFTER_IDD; } /** @type {number} */ var potentialCountryCode = this.extractCountryCode(fullNumber, @@ -3391,7 +3391,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.maybeExtractCountryCode = // If this fails, they must be using a strange country calling code that we // don't recognize, or that doesn't exist. - throw new Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE); + throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE; } else if (defaultRegionMetadata != null) { // Check to see if the number starts with the country calling code for the // default region. If so, we remove the country calling code, and do some @@ -3742,7 +3742,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseAndKeepRawInput = if (!this.isValidRegionCode_(defaultRegion)) { if (numberToParse.length > 0 && numberToParse.charAt(0) != i18n.phonenumbers.PhoneNumberUtil.PLUS_SIGN) { - throw new Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE); + throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE; } } return this.parseHelper_(numberToParse, defaultRegion, true, true); @@ -3801,10 +3801,10 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = function(numberToParse, defaultRegion, keepRawInput, checkRegion) { if (numberToParse == null) { - throw new Error(i18n.phonenumbers.Error.NOT_A_NUMBER); + throw i18n.phonenumbers.Error.NOT_A_NUMBER; } else if (numberToParse.length > i18n.phonenumbers.PhoneNumberUtil.MAX_INPUT_STRING_LENGTH_) { - throw new Error(i18n.phonenumbers.Error.TOO_LONG); + throw i18n.phonenumbers.Error.TOO_LONG; } /** @type {!goog.string.StringBuffer} */ @@ -3813,14 +3813,14 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = if (!i18n.phonenumbers.PhoneNumberUtil.isViablePhoneNumber( nationalNumber.toString())) { - throw new Error(i18n.phonenumbers.Error.NOT_A_NUMBER); + throw i18n.phonenumbers.Error.NOT_A_NUMBER; } // Check the region supplied is valid, or that the extracted number starts // with some sort of + sign so the number's region can be determined. if (checkRegion && !this.checkRegionForParsing_(nationalNumber.toString(), defaultRegion)) { - throw new Error(i18n.phonenumbers.Error.INVALID_COUNTRY_CODE); + throw i18n.phonenumbers.Error.INVALID_COUNTRY_CODE; } /** @type {i18n.phonenumbers.PhoneNumber} */ @@ -3850,7 +3850,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = countryCode = this.maybeExtractCountryCode(nationalNumberStr, regionMetadata, normalizedNationalNumber, keepRawInput, phoneNumber); } catch (e) { - if (e.message == i18n.phonenumbers.Error.INVALID_COUNTRY_CODE && + if (e == i18n.phonenumbers.Error.INVALID_COUNTRY_CODE && i18n.phonenumbers.PhoneNumberUtil.LEADING_PLUS_CHARS_PATTERN_ .test(nationalNumberStr)) { // Strip the plus-char, and try again. @@ -3888,7 +3888,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = } if (normalizedNationalNumber.getLength() < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) { - throw new Error(i18n.phonenumbers.Error.TOO_SHORT_NSN); + throw i18n.phonenumbers.Error.TOO_SHORT_NSN; } if (regionMetadata != null) { @@ -3913,11 +3913,11 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.parseHelper_ = var lengthOfNationalNumber = normalizedNationalNumberStr.length; if (lengthOfNationalNumber < i18n.phonenumbers.PhoneNumberUtil.MIN_LENGTH_FOR_NSN_) { - throw new Error(i18n.phonenumbers.Error.TOO_SHORT_NSN); + throw i18n.phonenumbers.Error.TOO_SHORT_NSN; } if (lengthOfNationalNumber > i18n.phonenumbers.PhoneNumberUtil.MAX_LENGTH_FOR_NSN_) { - throw new Error(i18n.phonenumbers.Error.TOO_LONG); + throw i18n.phonenumbers.Error.TOO_LONG; } this.setItalianLeadingZerosForPhoneNumber_( normalizedNationalNumberStr, phoneNumber); @@ -4041,7 +4041,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.isNumberMatch = firstNumber = this.parse( firstNumberIn, i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_); } catch (e) { - if (e.message != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { + if (e != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER; } // The first number has no country calling code. EXACT_MATCH is no longer @@ -4085,7 +4085,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.isNumberMatch = secondNumberIn, i18n.phonenumbers.PhoneNumberUtil.UNKNOWN_REGION_); return this.isNumberMatch(firstNumberIn, secondNumber); } catch (e) { - if (e.message != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { + if (e != i18n.phonenumbers.Error.INVALID_COUNTRY_CODE) { return i18n.phonenumbers.PhoneNumberUtil.MatchType.NOT_A_NUMBER; } return this.isNumberMatch(secondNumberIn, firstNumber);