36 lines
1004 B
TypeScript
36 lines
1004 B
TypeScript
import { config } from '../config';
|
|
|
|
/**
|
|
* Returns a client-safe error message. Internal details are hidden in production.
|
|
*/
|
|
export function clientErrorMessage(error: unknown, fallback = 'Request failed'): string {
|
|
const msg = error instanceof Error ? error.message : String(error);
|
|
const code = (error as { code?: string })?.code;
|
|
|
|
if (config.env !== 'production') {
|
|
return msg;
|
|
}
|
|
|
|
const exposeByCode = new Set([
|
|
'WITHDRAWALS_DISABLED',
|
|
'WITHDRAWAL_NETWORK_DISABLED',
|
|
'HOT_WALLET_INSUFFICIENT_LIQUIDITY',
|
|
'INSUFFICIENT_BALANCE',
|
|
'DAILY_WITHDRAWAL_LIMIT_EXCEEDED',
|
|
'WITHDRAWAL_2FA_REQUIRED',
|
|
]);
|
|
if (code && exposeByCode.has(code) && msg.trim()) {
|
|
return msg;
|
|
}
|
|
|
|
if (error instanceof Error && error.message) {
|
|
if (/^(Invalid|Unauthorized|Forbidden|Not found|2FA|Account|Password|Email|Phone|Referrer|referral)/i.test(msg)) {
|
|
return msg;
|
|
}
|
|
if (/Withdrawals are disabled/i.test(msg)) {
|
|
return msg;
|
|
}
|
|
}
|
|
return fallback;
|
|
}
|