mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
fix(RequestHandler): only reset tokens for authenticated 401s (#7508)
This commit is contained in:
@@ -357,9 +357,19 @@ test('Bad Request', async () => {
|
||||
});
|
||||
|
||||
test('Unauthorized', async () => {
|
||||
const setTokenSpy = jest.spyOn(invalidAuthApi.requestManager, 'setToken');
|
||||
|
||||
// Ensure authless requests don't reset the token
|
||||
const promiseWithoutTokenClear = invalidAuthApi.get('/unauthorized', { auth: false });
|
||||
await expect(promiseWithoutTokenClear).rejects.toThrowError('401: Unauthorized');
|
||||
await expect(promiseWithoutTokenClear).rejects.toBeInstanceOf(DiscordAPIError);
|
||||
expect(setTokenSpy).not.toHaveBeenCalled();
|
||||
|
||||
// Ensure authed requests do reset the token
|
||||
const promise = invalidAuthApi.get('/unauthorized');
|
||||
await expect(promise).rejects.toThrowError('401: Unauthorized');
|
||||
await expect(promise).rejects.toBeInstanceOf(DiscordAPIError);
|
||||
expect(setTokenSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('Reject on RateLimit', async () => {
|
||||
|
||||
Reference in New Issue
Block a user