mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
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:
@@ -451,7 +451,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
|||||||
|
|
||||||
rest.logger.debug(`sending request to ${url}`, 'with payload:', { ...payload, headers: loggingHeaders });
|
rest.logger.debug(`sending request to ${url}`, 'with payload:', { ...payload, headers: loggingHeaders });
|
||||||
const response = await fetch(request).catch(async (error) => {
|
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 });
|
rest.events.requestError(request, error, { body: options.requestBodyOptions?.body });
|
||||||
// Mark request as completed
|
// Mark request as completed
|
||||||
rest.invalidBucket.handleCompletedRequest(999, false);
|
rest.invalidBucket.handleCompletedRequest(999, false);
|
||||||
@@ -459,9 +459,13 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
|||||||
ok: false,
|
ok: false,
|
||||||
status: 999,
|
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.',
|
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}`);
|
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
|
// Sometimes the Content-Type may be "application/json; charset=utf-8", for this reason, we need to check the start of the header
|
||||||
|
|||||||
@@ -135,10 +135,10 @@ export class Queue {
|
|||||||
// Check if this request is able to be made globally
|
// Check if this request is able to be made globally
|
||||||
await this.rest.invalidBucket.waitUntilRequestAvailable();
|
await this.rest.invalidBucket.waitUntilRequestAvailable();
|
||||||
|
|
||||||
await this.rest
|
await this.rest.sendRequest(request).catch((e) => {
|
||||||
.sendRequest(request)
|
this.rest.logger.debug(`Queue ${this.queueType} ${this.url} encountered an error when sending a request.`, e);
|
||||||
// Should be handled in sendRequest, this catch just prevents bots from dying
|
request.reject({ ok: false, status: 999, error: 'The queue encontered an unexpected error sending a request.', errorObject: e });
|
||||||
.catch(() => null);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 */
|
/** The returned body parsed if it was JSON, otherwise it will be the raw body as a string */
|
||||||
body?: string | object;
|
body?: string | object;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
errorObject?: Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RestManagerEvents {
|
export interface RestManagerEvents {
|
||||||
|
|||||||
Reference in New Issue
Block a user