Skip to content

Commit

Permalink
add stack?
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Nov 14, 2024
1 parent 0b751c2 commit d4483fb
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/rest/betterRequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ class BetterRequestHandler {
(bucket.remaining === 0 &&
new Date().getTime() / 1000 > bucket.reset + this.#latency)
)
return this.#http(data.hash, data.request, data.params, data.body);
return this.#http(
data.hash,
data.request,
data.params,
data.body,
data._stack,
);
else {
this.#_client._emitDebug(
GLUON_DEBUG_LEVELS.WARN,
Expand All @@ -83,7 +89,13 @@ class BetterRequestHandler {
new Date().getTime() +
this.#fuzz,
);
return this.#http(data.hash, data.request, data.params, data.body);
return this.#http(
data.hash,
data.request,
data.params,
data.body,
data._stack,
);
}
};

Expand Down Expand Up @@ -173,11 +185,13 @@ class BetterRequestHandler {

while (retries--)
try {
const _stack = new Error().stack;
const result = await this.#queues[hash].push({
hash,
request,
params,
body,
_stack,
});
if (this.#queues[hash].idle()) delete this.#queues[hash];
return result;
Expand All @@ -188,7 +202,7 @@ class BetterRequestHandler {
throw new Error("GLUON: Request ran out of retries");
}

async #http(hash, request, params, body) {
async #http(hash, request, params, body, _stack) {
const actualRequest = this.#endpoints[request];

const path = actualRequest.path(...(params ?? []));
Expand Down Expand Up @@ -337,7 +351,7 @@ class BetterRequestHandler {
throw new Error(
`GLUON: ${res.status} ${actualRequest.method} ${actualRequest.path(
...(params ?? []),
)} ${json ? JSON.stringify(json) : ""} FAILED`,
)} ${json ? JSON.stringify(json) : ""} FAILED (stack): ${_stack}`,
);
} else {
const retryNextIn =
Expand All @@ -350,7 +364,9 @@ class BetterRequestHandler {
`READD ${hash} to request queue`,
);

throw new Error(`GLUON: 429 - Hit ratelimit, retry in ${retryNextIn}`);
throw new Error(
`GLUON: 429 - Hit ratelimit, retry in ${retryNextIn} (stack): ${_stack}`,
);
}
}
}
Expand Down

0 comments on commit d4483fb

Please sign in to comment.