Skip to content

Commit 3f86561

Browse files
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>
1 parent 883f6e9 commit 3f86561

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

packages/rest/src/lib/errors/HTTPError.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { STATUS_CODES } from 'node:http';
12
import type { InternalRequest } from '../RequestManager.js';
23
import type { RequestBody } from './DiscordAPIError.js';
34

@@ -7,21 +8,21 @@ import type { RequestBody } from './DiscordAPIError.js';
78
export class HTTPError extends Error {
89
public requestBody: RequestBody;
910

11+
public override name = HTTPError.name;
12+
1013
/**
11-
* @param name - The name of the error
1214
* @param status - The status code of the response
1315
* @param method - The method of the request that erred
1416
* @param url - The url of the request that erred
1517
* @param bodyData - The unparsed data for the request that errored
1618
*/
1719
public constructor(
18-
public override name: string,
1920
public status: number,
2021
public method: string,
2122
public url: string,
2223
bodyData: Pick<InternalRequest, 'body' | 'files'>,
2324
) {
24-
super();
25+
super(STATUS_CODES[status]);
2526

2627
this.requestBody = { files: bodyData.files, json: bodyData.body };
2728
}

packages/rest/src/lib/handlers/SequentialHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ export class SequentialHandler implements IHandler {
482482
}
483483

484484
// We are out of retries, throw an error
485-
throw new HTTPError(res.constructor.name, status, method, url, requestData);
485+
throw new HTTPError(status, method, url, requestData);
486486
} else {
487487
// Handle possible malformed requests
488488
if (status >= 400 && status < 500) {

0 commit comments

Comments
 (0)