From 9085f4a454de697dd855c122f46e0689f23d036f Mon Sep 17 00:00:00 2001 From: Fleny Date: Tue, 27 Jan 2026 18:41:37 +0100 Subject: [PATCH] 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 --- packages/rest/src/manager.ts | 8 ++++++-- packages/rest/src/queue.ts | 8 ++++---- packages/rest/src/types.ts | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index de3c42e99..16a4c5da7 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -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 diff --git a/packages/rest/src/queue.ts b/packages/rest/src/queue.ts index 74897a3cd..ff06c1bce 100644 --- a/packages/rest/src/queue.ts +++ b/packages/rest/src/queue.ts @@ -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 }); + }); } } diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index f48952486..b7c95d8d8 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -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 {