Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor exception messages #81

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/i18nify-js/src/modules/currency/formatNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof getCurrencySymbol>(getCurrencySymbol);
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading