Skip to content

Commit

Permalink
🔀 Merge pull request #1314 from TF2Autobot/fix-missing-catch
Browse files Browse the repository at this point in the history
🔨 Bypass checking listings if failed, just delete all on shutdown
  • Loading branch information
idinium96 authored Aug 14, 2022
2 parents 4f4e0fb + 432c751 commit 68b414b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
47 changes: 33 additions & 14 deletions src/classes/Listings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DictItem } from './Inventory';
import { PaintedNames } from './Options';
import ListingManager from '@tf2autobot/bptf-listings';
import getAttachmentName from '../lib/tools/getAttachmentName';
import filterAxiosError from '@tf2autobot/filter-axios-error';

export default class Listings {
private checkingAllListings = false;
Expand Down Expand Up @@ -446,24 +447,42 @@ export default class Listings {
this.bot.listingManager.actions.create = [];

// Wait for backpack.tf to finish creating / removing listings
void this.waitForListings().then(() => {
if (this.bot.listingManager.listings.length === 0) {
log.debug('We have no listings');
this.removingAllListings = false;
return resolve();
}
this.waitForListings()
.then(() => {
if (this.bot.listingManager.listings.length === 0) {
log.debug('We have no listings');
this.removingAllListings = false;
return resolve();
}

log.debug('Removing all listings...');
log.debug('Removing all listings...');

this.bot.listingManager.deleteAllListings(err => {
if (err) {
return reject(err);
}
this.bot.listingManager.deleteAllListings(err => {
if (err) {
return reject(err);
}

// The request might fail, if it does we will try again
return resolve(this.removeAllListings());
// The request might fail, if it does we will try again
return resolve(this.removeAllListings());
});
})
.catch(err => {
// if an error occurred, we bypass checking listings and just call delete all listings

log.error(
'Error getting listings info, force delete all listings. Error details: ',
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
filterAxiosError(err)
);
this.bot.listingManager.deleteAllListings(err => {
if (err) {
// But if failed to delete all listings, blame bptf 😴
return reject(err);
}

return resolve();
});
});
});
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,10 @@ export default class MyHandler extends Handler {
async onPricelist(pricelist: PricesObject): Promise<void> {
if (Object.keys(pricelist).length === 0) {
// Ignore errors
await this.bot.listings.removeAll();
await this.bot.listings.removeAll().catch(err => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
log.error('Error on removing all listings: ', filterAxiosError(err));
});
}

/*
Expand Down

0 comments on commit 68b414b

Please sign in to comment.