aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-05-09 20:05:14 -0500
committermat <github@matdoes.dev>2021-05-09 20:05:14 -0500
commit58807d12eefe264e817d8dc4b7075dbb25e4c2d2 (patch)
tree53f7c02ea6cddcc5c053da56e57ddbc5755b02ac
parent919a610cf5fcb8c4714a3be147ab5461778bbf2f (diff)
downloadskyblock-api-58807d12eefe264e817d8dc4b7075dbb25e4c2d2.tar.gz
skyblock-api-58807d12eefe264e817d8dc4b7075dbb25e4c2d2.tar.bz2
skyblock-api-58807d12eefe264e817d8dc4b7075dbb25e4c2d2.zip
temp debug stuff
-rw-r--r--build/constants.js4
-rw-r--r--build/hypixelApi.js8
-rw-r--r--build/index.js2
-rw-r--r--src/constants.ts4
-rw-r--r--src/hypixelApi.ts9
-rw-r--r--src/index.ts2
6 files changed, 23 insertions, 6 deletions
diff --git a/build/constants.js b/build/constants.js
index 3c0c7e9..b657426 100644
--- a/build/constants.js
+++ b/build/constants.js
@@ -64,7 +64,8 @@ async function fetchGithubApi(method, route, headers, json) {
}, headers),
});
}
- catch {
+ catch (err) {
+ console.log('bruh, errored', err);
// if there's an error, wait a second and try again
await new Promise((resolve) => setTimeout(resolve, 1000));
return await fetchGithubApi(method, route, headers, json);
@@ -89,6 +90,7 @@ function fetchFile(path) {
'Accept': 'application/vnd.github.v3+json',
});
const data = await r.json();
+ console.log('ok github api returned');
const file = {
path: data.path,
content: Buffer.from(data.content, data.encoding).toString(),
diff --git a/build/hypixelApi.js b/build/hypixelApi.js
index ccae09b..b0d87fe 100644
--- a/build/hypixelApi.js
+++ b/build/hypixelApi.js
@@ -58,7 +58,8 @@ async function sendApiRequest({ path, key, args }) {
fetchResponse = await node_fetch_1.default(fetchUrl, { agent: () => httpsAgent });
fetchJsonParsed = await fetchResponse.json();
}
- catch {
+ catch (err) {
+ console.debug('error? ok retrying', err);
// if there's an error, wait a second and try again
await new Promise((resolve) => setTimeout(resolve, 1000));
return await sendApiRequest({ path, key, args });
@@ -76,12 +77,17 @@ async function sendApiRequest({ path, key, args }) {
reset: Date.now() + parseInt(fetchResponse.headers['ratelimit-reset']) * 1000
};
if (fetchJsonParsed.throttle) {
+ console.log('bruh, throttled');
if (apiKeyUsage[key])
apiKeyUsage[key].remaining = 0;
// if it's throttled, wait 10 seconds and try again
await new Promise((resolve) => setTimeout(resolve, 10000));
return await sendApiRequest({ path, key, args });
}
+ console.log(path, args, fetchJsonParsed.success);
+ if (!fetchJsonParsed.success) {
+ console.log(fetchJsonParsed);
+ }
return fetchJsonParsed;
}
exports.sendApiRequest = sendApiRequest;
diff --git a/build/index.js b/build/index.js
index c7f1385..ba1e21a 100644
--- a/build/index.js
+++ b/build/index.js
@@ -29,7 +29,7 @@ const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
const constants = __importStar(require("./constants"));
const express_1 = __importDefault(require("express"));
const app = express_1.default();
-exports.debug = false;
+exports.debug = true;
// 200 requests over 5 minutes
const limiter = express_rate_limit_1.default({
windowMs: 60 * 1000 * 5,
diff --git a/src/constants.ts b/src/constants.ts
index 52c104c..6c5c1c5 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -47,7 +47,8 @@ async function fetchGithubApi(method: string, route: string, headers?: any, json
}, headers),
}
)
- } catch {
+ } catch (err) {
+ console.log('bruh, errored', err)
// if there's an error, wait a second and try again
await new Promise((resolve) => setTimeout(resolve, 1000))
return await fetchGithubApi(method, route, headers, json)
@@ -86,6 +87,7 @@ function fetchFile(path: string): Promise<GithubFile> {
},
)
const data = await r.json()
+ console.log('ok github api returned')
const file = {
path: data.path,
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts
index fdb4535..35d46cb 100644
--- a/src/hypixelApi.ts
+++ b/src/hypixelApi.ts
@@ -145,7 +145,8 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon
{ agent: () => httpsAgent }
)
fetchJsonParsed = await fetchResponse.json()
- } catch {
+ } catch (err) {
+ console.debug('error? ok retrying', err)
// if there's an error, wait a second and try again
await new Promise((resolve) => setTimeout(resolve, 1000))
return await sendApiRequest({ path, key, args })
@@ -166,12 +167,18 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon
}
if (fetchJsonParsed.throttle) {
+ console.log('bruh, throttled')
if (apiKeyUsage[key])
apiKeyUsage[key].remaining = 0
// if it's throttled, wait 10 seconds and try again
await new Promise((resolve) => setTimeout(resolve, 10000))
return await sendApiRequest({ path, key, args })
}
+
+ console.log(path, args, fetchJsonParsed.success)
+ if (!fetchJsonParsed.success) {
+ console.log(fetchJsonParsed)
+ }
return fetchJsonParsed
}
diff --git a/src/index.ts b/src/index.ts
index 1652428..6f3b94f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -6,7 +6,7 @@ import express from 'express'
const app = express()
-export const debug = false
+export const debug = true
// 200 requests over 5 minutes