From a00e3d77b84d232f386d5295edfde47ae0718a9b Mon Sep 17 00:00:00 2001 From: RgnDunes Date: Fri, 23 Feb 2024 17:51:54 +0530 Subject: [PATCH] refactor exception messages --- packages/i18nify-js/src/modules/currency/formatNumber.ts | 2 +- packages/i18nify-js/src/modules/currency/formatNumberByParts.ts | 2 +- packages/i18nify-js/src/modules/currency/getCurrencySymbol.ts | 2 +- .../i18nify-js/src/modules/phoneNumber/formatPhoneNumber.ts | 2 +- packages/i18nify-js/src/modules/phoneNumber/parsePhoneNumber.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/i18nify-js/src/modules/currency/formatNumber.ts b/packages/i18nify-js/src/modules/currency/formatNumber.ts index de727d17..817e4772 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumber.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumber.ts @@ -12,7 +12,7 @@ const formatNumber = ( } = {}, ): string => { if (!Number(amount) && Number(amount) !== 0) - throw new Error('Parameter `amount` is not a number!'); + throw new Error(`Parameter 'amount' is not a number. Typeof amount is : ${typeof amount}`); let formattedAmount = ''; diff --git a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts index 6165d137..bee03bc3 100644 --- a/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts +++ b/packages/i18nify-js/src/modules/currency/formatNumberByParts.ts @@ -17,7 +17,7 @@ const formatNumberByParts = ( } = {}, ): ByParts => { if (!Number(amount) && Number(amount) !== 0) - throw new Error('Parameter `amount` is not a number!'); + throw new Error(`Parameter 'amount' is not a number. Typeof amount is : ${typeof amount}`); try { const formattedAmount = getIntlInstanceWithOptions(options).formatToParts( diff --git a/packages/i18nify-js/src/modules/currency/getCurrencySymbol.ts b/packages/i18nify-js/src/modules/currency/getCurrencySymbol.ts index d9381f83..e4cf0359 100644 --- a/packages/i18nify-js/src/modules/currency/getCurrencySymbol.ts +++ b/packages/i18nify-js/src/modules/currency/getCurrencySymbol.ts @@ -4,7 +4,7 @@ import { CurrencyCodeType } from './types'; const getCurrencySymbol = (currencyCode: CurrencyCodeType): string => { if (currencyCode in CURRENCIES) return CURRENCIES[currencyCode]?.symbol; - else throw new Error('Invalid currencyCode!'); + else throw new Error(`Invalid currencyCode: ${currencyCode}`); }; export default withErrorBoundary(getCurrencySymbol); diff --git a/packages/i18nify-js/src/modules/phoneNumber/formatPhoneNumber.ts b/packages/i18nify-js/src/modules/phoneNumber/formatPhoneNumber.ts index 97a661a6..4ff54cc0 100644 --- a/packages/i18nify-js/src/modules/phoneNumber/formatPhoneNumber.ts +++ b/packages/i18nify-js/src/modules/phoneNumber/formatPhoneNumber.ts @@ -8,7 +8,7 @@ const formatPhoneNumber = ( countryCode?: keyof typeof PHONE_FORMATTER_MAPPER, ): string => { // Throw errors if phoneNumber is invalid - if (!phoneNumber) throw new Error('Parameter `phoneNumber` is invalid!'); + if (!phoneNumber) throw new Error(`Parameter 'phoneNumber' is invalid: ${phoneNumber}`); // Convert phoneNumber to string and clean it by removing non-numeric characters phoneNumber = phoneNumber.toString(); diff --git a/packages/i18nify-js/src/modules/phoneNumber/parsePhoneNumber.ts b/packages/i18nify-js/src/modules/phoneNumber/parsePhoneNumber.ts index be61d2ef..2c52b258 100644 --- a/packages/i18nify-js/src/modules/phoneNumber/parsePhoneNumber.ts +++ b/packages/i18nify-js/src/modules/phoneNumber/parsePhoneNumber.ts @@ -13,7 +13,7 @@ interface PhoneInfo { // Parses a given phone number, identifies its country code (if not provided), and returns an object with details including the country code, formatted phone number, dial code, and format template. const parsePhoneNumber = (phoneNumber: string, country?: string): PhoneInfo => { // Throw errors if phoneNumber is invalid - if (!phoneNumber) throw new Error('Parameter `phoneNumber` is invalid!'); + if (!phoneNumber) throw new Error(`Parameter 'phoneNumber' is invalid: ${phoneNumber}`); // Clean the phoneNumber by removing non-numeric characters phoneNumber = phoneNumber.toString();