fix(rest): Make sure to not suppress non-api errors (#4691)

Queues currenly suppress errors, making it very hard to figure out if there is a parse error for example
This fixes it as it add debug logs and passes the error object along with the rejection in sendRequest and does reject the promise in the queue instead of silently ignoring it
This commit is contained in:
Fleny
2026-01-27 18:41:37 +01:00
committed by GitHub
parent e41b0bce4d
commit 9085f4a454
3 changed files with 11 additions and 6 deletions

View File

@@ -451,7 +451,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
rest.logger.debug(`sending request to ${url}`, 'with payload:', { ...payload, headers: loggingHeaders });
const response = await fetch(request).catch(async (error) => {
rest.logger.error(error);
rest.logger.debug(`request fetch to ${url} failed.`, error);
rest.events.requestError(request, error, { body: options.requestBodyOptions?.body });
// Mark request as completed
rest.invalidBucket.handleCompletedRequest(999, false);
@@ -459,9 +459,13 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
ok: false,
status: 999,
error: 'Possible network or request shape issue occurred. If this is rare, its a network glitch. If it occurs a lot something is wrong.',
errorObject: error,
});
throw error;
});
// If response is undefined, the error has been handled in the catch block above
if (!response) return;
rest.logger.debug(`request fetched from ${url} with status ${response.status} & ${response.statusText}`);
// Sometimes the Content-Type may be "application/json; charset=utf-8", for this reason, we need to check the start of the header

View File

@@ -135,10 +135,10 @@ export class Queue {
// Check if this request is able to be made globally
await this.rest.invalidBucket.waitUntilRequestAvailable();
await this.rest
.sendRequest(request)
// Should be handled in sendRequest, this catch just prevents bots from dying
.catch(() => null);
await this.rest.sendRequest(request).catch((e) => {
this.rest.logger.debug(`Queue ${this.queueType} ${this.url} encountered an error when sending a request.`, e);
request.reject({ ok: false, status: 999, error: 'The queue encontered an unexpected error sending a request.', errorObject: e });
});
}
}

View File

@@ -3287,6 +3287,7 @@ export interface RestRequestRejection {
/** The returned body parsed if it was JSON, otherwise it will be the raw body as a string */
body?: string | object;
error?: string;
errorObject?: Error;
}
export interface RestManagerEvents {