mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
fix(SequentialHandler): throw http error with proper name and more useful message (#8694)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { STATUS_CODES } from 'node:http';
|
||||||
import type { InternalRequest } from '../RequestManager.js';
|
import type { InternalRequest } from '../RequestManager.js';
|
||||||
import type { RequestBody } from './DiscordAPIError.js';
|
import type { RequestBody } from './DiscordAPIError.js';
|
||||||
|
|
||||||
@@ -7,21 +8,21 @@ import type { RequestBody } from './DiscordAPIError.js';
|
|||||||
export class HTTPError extends Error {
|
export class HTTPError extends Error {
|
||||||
public requestBody: RequestBody;
|
public requestBody: RequestBody;
|
||||||
|
|
||||||
|
public override name = HTTPError.name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name - The name of the error
|
|
||||||
* @param status - The status code of the response
|
* @param status - The status code of the response
|
||||||
* @param method - The method of the request that erred
|
* @param method - The method of the request that erred
|
||||||
* @param url - The url of the request that erred
|
* @param url - The url of the request that erred
|
||||||
* @param bodyData - The unparsed data for the request that errored
|
* @param bodyData - The unparsed data for the request that errored
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
public override name: string,
|
|
||||||
public status: number,
|
public status: number,
|
||||||
public method: string,
|
public method: string,
|
||||||
public url: string,
|
public url: string,
|
||||||
bodyData: Pick<InternalRequest, 'body' | 'files'>,
|
bodyData: Pick<InternalRequest, 'body' | 'files'>,
|
||||||
) {
|
) {
|
||||||
super();
|
super(STATUS_CODES[status]);
|
||||||
|
|
||||||
this.requestBody = { files: bodyData.files, json: bodyData.body };
|
this.requestBody = { files: bodyData.files, json: bodyData.body };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ export class SequentialHandler implements IHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We are out of retries, throw an error
|
// We are out of retries, throw an error
|
||||||
throw new HTTPError(res.constructor.name, status, method, url, requestData);
|
throw new HTTPError(status, method, url, requestData);
|
||||||
} else {
|
} else {
|
||||||
// Handle possible malformed requests
|
// Handle possible malformed requests
|
||||||
if (status >= 400 && status < 500) {
|
if (status >= 400 && status < 500) {
|
||||||
|
|||||||
Reference in New Issue
Block a user