chore: improve error message

This commit is contained in:
apotdevin 2021-06-01 22:20:29 +02:00
parent 66c30891af
commit 6a8da2e6fe
No known key found for this signature in database
GPG key ID: 4403F1DFBE779457
3 changed files with 15 additions and 21 deletions

View file

@ -16,15 +16,11 @@ export const getIp = (req: any) => {
};
export const getErrorMsg = (error: any[] | string): string => {
if (typeof error === 'string') {
return error;
}
if (error.length >= 2) {
return error[1];
}
// if (error.length > 2) {
// return error[2].err?.message || 'Error';
// }
console.log(error);
if (!error) return 'Unknown Error';
if (typeof error === 'string') return error;
if (error[2]?.err?.details) return error[2]?.err?.details;
if (error[1]) return error[1];
return 'Error';
return 'Unkown Error';
};

View file

@ -8,9 +8,7 @@ import {
getPendingChannels,
} from 'ln-service';
import { ContextType } from 'server/types/apiTypes';
import { logger } from 'server/helpers/logger';
import { requestLimiter } from 'server/helpers/rateLimiter';
import { getErrorMsg } from 'server/helpers/helpers';
import { sortBy } from 'underscore';
import { to } from 'server/helpers/async';
import {
@ -114,18 +112,15 @@ export const chainResolvers = {
const format = params.nested ? 'np2wpkh' : 'p2wpkh';
try {
const address = await createChainAddress({
const address = await to<{ address: string }>(
createChainAddress({
lnd,
is_unused: true,
format,
});
})
);
return address.address;
} catch (error) {
logger.error('Error creating address: %o', error);
throw new Error(getErrorMsg(error));
}
return address.address;
},
sendToAddress: async (_: undefined, params: any, context: ContextType) => {
await requestLimiter(context.ip, 'sendToAddress');

View file

@ -55,7 +55,10 @@ export const UtxoCard = ({
{renderLine('Confirmations: ', confirmation_count)}
{renderLine('Output Script: ', output_script)}
{renderLine('Transaction Id: ', getTransactionLink(transaction_id))}
{renderLine('Transaction Vout: ', transaction_vout)}
{renderLine(
'Transaction Vout: ',
transaction_vout >= 0 ? `${transaction_vout}` : '-'
)}
</>
);
};