-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
502 error handling #45
base: master
Are you sure you want to change the base?
Conversation
} | ||
if (status >= 400) { | ||
} else if (status === 502) { | ||
this.rateLimitWaits[type] = 10 * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wait seconds should probably be in a const.
Hey! This sounds like a good idea, but I have a few questions: First, about the change from
If the status is 429 - the function should return there and never reach the next line. So it shouldn't matter if it's if or else if. My second question is about the change itself. Is this something you've actually experienced and tested this fixes? It sounds like you're right from the API docs, but we try to reproduce this and see your solution fixes it. |
Hey there, my mistake, I misinterpreted the return behavior of the function. As for the 502 change, I haven't been able to reproduce it since it originally happened to me, but I have tested by changing the fetch function: const realFetch = fetch;
let return502 = true;
fetch = async function() {
let response = await realFetch(...arguments);
if (return502 && typeof arguments[0] === "string" && arguments[0].includes("discordapp.com")) {
console.log("hijacking");
return502 = false;
return { // returns a fake 502 response object for the first request
status: 502,
headers: response.headers,
body: null,
async text() {
return "whatever it returns"
}
}
}
return response;
} This works with the changes that I made, but what I'm noticing now is that in my original screenshot, the error originated from line 84, which is the fetch function call. So I think some additional changes would have to be made to the fetch call to handle the error, maybe something like this: const response = await fetch(`${this.baseUrl}${path}`, {
method: method,
body: body,
}).catch(e => {}); // catching errors Although what I'm not sure about is why fetch threw an error. Fetch shouldn't reject on HTTP errors: https://developer.mozilla.org/en-US/docs/Web/API/fetch |
Bet it doesn't in FF |
The Discord API can sometimes return status code 502. According to their docs, you just have to "wait a bit and retry" your request (https://discord.com/developers/docs/topics/opcodes-and-status-codes).
This can be problematic when there isn't proper error handling because file uploads can be interrupted and will never complete. Waiting an arbitrary amount of time (like 10 seconds) and then retrying the request should fix this.
Additionally, if one or more requests return status code 429, line 102 (
throw new Error(...);
) will ALWAYS run after all recursive calls tothis.fetchFromApi
finish. This means that errors will populate the console even if the upload succeeded with rate limits. I'm not sure if this is intentional, but I changed the conditional to anelse if
block just in case. Changes are welcomed