mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-19 13:22:11 +00:00
fix: handle rate limiting&request errors correctly
This commit is contained in:
parent
e36445de70
commit
b1f2d87d74
2 changed files with 9 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Miru",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
|
||||
"main": "src/index.js",
|
||||
"homepage": "https://github.com/ThaUnknown/miru#readme",
|
||||
|
|
|
|||
|
|
@ -87,18 +87,21 @@ const limit = limiter.wrap(handleRequest)
|
|||
|
||||
async function handleRequest (opts) {
|
||||
const res = await fetch('https://graphql.anilist.co', opts)
|
||||
if (!res.ok && res.status === 429) return await limit(opts)
|
||||
let json = null
|
||||
try {
|
||||
json = await res.json()
|
||||
} catch (error) {
|
||||
if (res.ok) printError(error)
|
||||
if (error.status === 429) return await limit(opts)
|
||||
}
|
||||
if (!res.ok && json) {
|
||||
for (const error of json?.errors || []) {
|
||||
printError(error)
|
||||
if (!res.ok) {
|
||||
if (json) {
|
||||
for (const error of json?.errors || []) {
|
||||
printError(error)
|
||||
}
|
||||
} else {
|
||||
printError(res)
|
||||
}
|
||||
if (res.status === 429) return await limit(opts)
|
||||
}
|
||||
return json
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue