mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
feat(rest): Improve rest errors (#3382)
* Improve rest errors * formatting
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
/* eslint-disable no-const-assign */
|
||||
import { Buffer } from 'node:buffer'
|
||||
|
||||
import { calculateBits, camelize, camelToSnakeCase, delay, getBotIdFromToken, logger, processReactionString, urlToBase64 } from '@discordeno/utils'
|
||||
@@ -479,6 +477,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
return result.status !== 204 ? await result.json() : undefined
|
||||
}
|
||||
|
||||
// This error needs to be created here because of how stack traces get calculated
|
||||
const error = new Error()
|
||||
error.message = 'Failed to send request to discord.'
|
||||
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return await new Promise(async (resolve, reject) => {
|
||||
const payload: SendRequestOptions = {
|
||||
@@ -486,13 +488,16 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
method,
|
||||
requestBodyOptions: options,
|
||||
retryCount: 0,
|
||||
retryRequest: async function (payload: SendRequestOptions) {
|
||||
retryRequest: async (payload: SendRequestOptions) => {
|
||||
await rest.processRequest(payload)
|
||||
},
|
||||
resolve: (data) => {
|
||||
resolve(data.status !== 204 ? JSON.parse(data.body ?? '{}') : undefined)
|
||||
},
|
||||
reject,
|
||||
reject: (reason) => {
|
||||
error.cause = reason
|
||||
reject(error)
|
||||
},
|
||||
runThroughQueue: options?.runThroughQueue,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user