aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/error_description.ts
blob: 9419a1e162392cc09bc102abf286324f576847cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { AssetBuyerError } from '@0xproject/asset-buyer';

import { assetDataUtil } from '../util/asset_data';

const humanReadableMessageForError = (error: Error, assetData?: string): string | undefined => {
    if (error.message === AssetBuyerError.InsufficientAssetLiquidity) {
        const assetName = assetDataUtil.bestNameForAsset(assetData, 'of this asset');
        return `Not enough ${assetName} available`;
    }

    return undefined;
};

export const errorDescription = (error?: any, assetData?: string): { icon: string; message: string } => {
    let bestMessage: string | undefined;
    if (error instanceof Error) {
        bestMessage = humanReadableMessageForError(error, assetData);
    }
    return {
        icon: '😢',
        message: bestMessage || 'Something went wrong...',
    };
};