Skip to content

Commit

Permalink
fix(SequentialHandler): throw http error with proper name and more us…
Browse files Browse the repository at this point in the history
…eful message (#8694)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
SpaceEEC and kodiakhq[bot] committed Oct 1, 2022
1 parent 883f6e9 commit 3f86561
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/rest/src/lib/errors/HTTPError.ts
@@ -1,3 +1,4 @@
import { STATUS_CODES } from 'node:http';
import type { InternalRequest } from '../RequestManager.js';
import type { RequestBody } from './DiscordAPIError.js';

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

public override name = HTTPError.name;

/**
* @param name - The name of the error
* @param status - The status code of the response
* @param method - The method of the request that erred
* @param url - The url of the request that erred
* @param bodyData - The unparsed data for the request that errored
*/
public constructor(
public override name: string,
public status: number,
public method: string,
public url: string,
bodyData: Pick<InternalRequest, 'body' | 'files'>,
) {
super();
super(STATUS_CODES[status]);

this.requestBody = { files: bodyData.files, json: bodyData.body };
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/lib/handlers/SequentialHandler.ts
Expand Up @@ -482,7 +482,7 @@ export class SequentialHandler implements IHandler {
}

// 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 {
// Handle possible malformed requests
if (status >= 400 && status < 500) {
Expand Down

0 comments on commit 3f86561

Please sign in to comment.