catch status properly
This commit is contained in:
1 parent
b340fc7b61
commit
ae83ad54c4
2 files changed
+5
-12
No files matched your search
+4
-11
@@ -79,17 +79,9 @@ export default async function createDiscogs(log: Log, pg: Pg) {
|
||||
const url = `https://www.discogs.com/sell/release/${want.release}?limit=250`
|
||||
|
||||
log.info({ url }, 'fetching')
|
||||
|
||||
const res = await page.goto(url)
|
||||
|
||||
log.info(res)
|
||||
|
||||
----------------
|
||||
|
||||
|
||||
not catching the rate limiting here i thnk
|
||||
|
||||
if (res.status() === 429) throw new Error("rate limited")
|
||||
log.debug({ status: res.status() }, 'status')
|
||||
if (!res.ok()) throw new Error(res.statusText())
|
||||
|
||||
const els = await page.$$('.item_description_title[href]')
|
||||
const hrefs = await Promise.all(els.map(e => e.evaluate(e => e.href)))
|
||||
@@ -112,7 +104,8 @@ export default async function createDiscogs(log: Log, pg: Pg) {
|
||||
const validListings = results
|
||||
.map(r => {
|
||||
if (r.status === 'fulfilled') return r.value;
|
||||
if (r.reason.message.includes('rate limited')) throw r.reason;
|
||||
if (r.reason.response.status === 429) throw r.reason;
|
||||
log.warn('listing fetch error', r)
|
||||
return null
|
||||
})
|
||||
.filter(v => v);
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers, discord)
|
||||
return listings;
|
||||
} catch (e) {
|
||||
log.error(e)
|
||||
if (e.status === 429) {
|
||||
if (e.response.status === 429) {
|
||||
log.warn('rate limited, trying again in 60s');
|
||||
await setTimeout(60 * 1000);
|
||||
if (attempts > MAX_ATTEMPTS) {
|
||||
|
||||
Reference in new issue
Block a user