From 3f8656115bf9df0dbf8391de68a3401535325895 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Sat, 1 Oct 2022 16:50:18 +0200 Subject: [PATCH] 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> --- packages/rest/src/lib/errors/HTTPError.ts | 7 ++++--- packages/rest/src/lib/handlers/SequentialHandler.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/rest/src/lib/errors/HTTPError.ts b/packages/rest/src/lib/errors/HTTPError.ts index 14912e77a716..d9859e9400e8 100644 --- a/packages/rest/src/lib/errors/HTTPError.ts +++ b/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'; @@ -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, ) { - super(); + super(STATUS_CODES[status]); this.requestBody = { files: bodyData.files, json: bodyData.body }; } diff --git a/packages/rest/src/lib/handlers/SequentialHandler.ts b/packages/rest/src/lib/handlers/SequentialHandler.ts index ef90ef43bc32..60ca20851f91 100644 --- a/packages/rest/src/lib/handlers/SequentialHandler.ts +++ b/packages/rest/src/lib/handlers/SequentialHandler.ts @@ -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) {