aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util/error_description.ts
blob: 78af9e9ff53cf471f39efc3469beaff1b765e5ea (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 { bestNameForAsset } from '../util/asset_data';

const humanReadableMessageForError = (error: Error, assetData?: string): string | undefined => {
    if (error.message === AssetBuyerError.InsufficientAssetLiquidity) {
        const assetName = 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...',
    };
};