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 {