fix errors for discogs and use env settings in mcrates compose
This commit is contained in:
1 parent
2ffb5f9bc3
commit
ac0a31511d
4 files changed
+17
-9
No files matched your search
+3
-3
@@ -42,7 +42,6 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
}
|
||||
|
||||
function onError(error) {
|
||||
console.error(error);
|
||||
if (error.response.status === 429) {
|
||||
return [new Error('rate limited, try again in 1 minute'), null];
|
||||
}
|
||||
@@ -54,7 +53,6 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
|
||||
async function wantListSync(username: string, user: User): Promise<Want[]> {
|
||||
const [err, res] = await api.get(`${apiBase}/users/${username}/wants`);
|
||||
log.warn(err, res);
|
||||
if (err) throw err;
|
||||
const { wants, pagination } = res;
|
||||
|
||||
@@ -75,7 +73,8 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
}
|
||||
|
||||
async function release(id: DiscogsRelease): Promise<any> {
|
||||
const [error, data] = await api.get(`${apiBase}/releases/${id}`);
|
||||
const [err, data] = await api.get(`${apiBase}/releases/${id}`);
|
||||
if (err) throw err;
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -121,6 +120,7 @@ export default function createDiscogs(log: Log, pg: Pg) {
|
||||
|
||||
log.debug('fetching listing', id);
|
||||
const [err, discogsListing] = await api.get(`${apiBase}/marketplace/listings/${id}`);
|
||||
if (err) throw err;
|
||||
log.debug(discogsListing);
|
||||
return pg.listingUpsert(discogsListing, want);
|
||||
}
|
||||
|
||||
+6
-2
@@ -27,7 +27,8 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
|
||||
log.error('event error', e);
|
||||
});
|
||||
|
||||
async function populateListings(want: Want) {
|
||||
const MAX_ATTEMPTS = 2;
|
||||
async function populateListings(want: Want, attempts = 0) {
|
||||
try {
|
||||
const listings = await discogs.listings(want);
|
||||
await pg.wantSynced(want);
|
||||
@@ -36,7 +37,10 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
|
||||
if (e.message.includes('rate limited')) {
|
||||
log.warn('rate limited, trying again in 60s');
|
||||
await setTimeout(60 * 1000);
|
||||
return populateListings(want);
|
||||
if (attempts > MAX_ATTEMPTS) {
|
||||
log.error(wantDetails(want), 'failed to populate listings')
|
||||
}
|
||||
return populateListings(want, attempts++);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user