mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(rest): errors returned from makeRequest() doesn't provide more info rest is proxied (#4012)
This commit is contained in:
@@ -533,6 +533,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
},
|
||||
|
||||
async makeRequest(method, route, options) {
|
||||
// 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.'
|
||||
|
||||
if (rest.isProxied) {
|
||||
if (rest.authorization) {
|
||||
options ??= {}
|
||||
@@ -543,19 +547,28 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
const result = await fetch(`${rest.baseUrl}/v${rest.version}${route}`, rest.createRequestBody(method, options))
|
||||
|
||||
if (!result.ok) {
|
||||
const errText = await result.text().catch(() => null)
|
||||
|
||||
if (errText) {
|
||||
error.cause = {
|
||||
ok: false,
|
||||
status: result.status,
|
||||
body: errText,
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
|
||||
const err = (await result.json().catch(() => {})) as Record<string, any>
|
||||
// Legacy Handling to not break old code or when body is missing
|
||||
if (!err?.body) throw new Error(`Error: ${err.message ?? result.statusText}`)
|
||||
|
||||
throw new Error(JSON.stringify(err))
|
||||
}
|
||||
|
||||
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.'
|
||||
|
||||
return await new Promise(async (resolve, reject) => {
|
||||
const payload: SendRequestOptions = {
|
||||
route,
|
||||
|
||||
Reference in New Issue
Block a user