mirror of
https://github.com/LBRYFoundation/curate.git
synced 2025-08-23 17:37:25 +00:00
Fix error handling
This commit is contained in:
parent
f9b5603534
commit
0432967787
4 changed files with 10 additions and 8 deletions
|
@ -10,8 +10,8 @@ module.exports = class AdminBalance extends Command {
|
|||
|
||||
async exec(message) {
|
||||
const response = await this.client.lbry.walletBalance();
|
||||
if (await this.handleResponse(message, response)) return;
|
||||
const wallet = await response.json();
|
||||
if (await this.handleResponse(message, response, wallet)) return;
|
||||
return message.channel.createMessage({ embed: {
|
||||
description: `**Available:** ${wallet.result.available} LBC\n\n` +
|
||||
`Reserved in Supports: ${wallet.result.reserved_subtotals.supports} LBC\n` +
|
||||
|
|
|
@ -10,8 +10,8 @@ module.exports = class Deposit extends Command {
|
|||
|
||||
async exec(message) {
|
||||
const response = await this.client.lbry.listAddresses();
|
||||
if (await this.handleResponse(message, response)) return;
|
||||
const address = await response.json();
|
||||
if (await this.handleResponse(message, response, address)) return;
|
||||
return message.channel.createMessage(`Address: ${address.result.items[0].address}`);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,16 +17,17 @@ module.exports = class Withdraw extends Command {
|
|||
|
||||
// Check if the balance is more than requested
|
||||
const balance = await this.client.lbry.walletBalance();
|
||||
if (await this.handleResponse(message, balance)) return;
|
||||
const availableBalance = parseFloat((await balance.json()).result.available);
|
||||
const balanceJSON = await balance.json();
|
||||
if (await this.handleResponse(message, balance, balanceJSON)) return;
|
||||
const availableBalance = parseFloat(balanceJSON.result.available);
|
||||
if (parseFloat(amount) > availableBalance)
|
||||
return message.channel.createMessage(
|
||||
'There is not enough available LBC in the wallet to send that amount!');
|
||||
|
||||
// Send to wallet
|
||||
const response = await this.client.lbry.sendToWallet({ amount, to: args[1] });
|
||||
if (await this.handleResponse(message, response)) return;
|
||||
const transaction = await response.json();
|
||||
if (await this.handleResponse(message, response, transaction)) return;
|
||||
console.debug('withdrew from master wallet', transaction);
|
||||
return message.channel.createMessage(`Sent ${parseFloat(amount)} LBC to ${args[1]}.\n` +
|
||||
`https://explorer.lbry.com/tx/${transaction.result.txid}`);
|
||||
|
|
|
@ -81,10 +81,11 @@ class Command {
|
|||
/**
|
||||
* @private
|
||||
*/
|
||||
async handleResponse(message, response) {
|
||||
if (response.status !== 200) {
|
||||
async handleResponse(message, response, json) {
|
||||
if (!json) json = await response.json();
|
||||
if (response.status !== 200 || json.error) {
|
||||
const error = response.status === 500 ?
|
||||
{ message: 'Internal server error' } : (await response.json()).error;
|
||||
{ message: 'Internal server error' } : json.error;
|
||||
console.error(`SDK error in ${this.name}:${message.author.id}`, response, error);
|
||||
await message.channel.createMessage(`LBRY-SDK returned ${response.status}.\n${error.message}`);
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue