mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix: Rest proxy error (#2471)
* Rebase Update on main * Rebase Update on main * Rebase Update on main * Fix deno fmt Co-authored-by: meister03 <meisterpi@gmail.com>
This commit is contained in:
+7
-5
@@ -23,6 +23,10 @@ export async function runMethod<T = any>(
|
|||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const errorStack = new Error("Location:");
|
||||||
|
// @ts-ignore Breaks deno deploy. Luca said add ts-ignore until it's fixed
|
||||||
|
Error.captureStackTrace(errorStack);
|
||||||
|
|
||||||
// For proxies we don't need to do any of the legwork so we just forward the request
|
// For proxies we don't need to do any of the legwork so we just forward the request
|
||||||
if (!baseEndpoints.BASE_URL.startsWith(BASE_URL) && route[0] === "/") {
|
if (!baseEndpoints.BASE_URL.startsWith(BASE_URL) && route[0] === "/") {
|
||||||
const result = await fetch(`${baseEndpoints.BASE_URL}${route}`, {
|
const result = await fetch(`${baseEndpoints.BASE_URL}${route}`, {
|
||||||
@@ -36,16 +40,14 @@ export async function runMethod<T = any>(
|
|||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
const err = await result.json().catch(() => {});
|
const err = await result.json().catch(() => {});
|
||||||
throw new Error(`Error: ${err.message ?? result.statusText}`);
|
// Legacy Handling to not break old code or when body is missing
|
||||||
|
if (!err.body) throw new Error(`Error: ${err.message ?? result.statusText}`);
|
||||||
|
throw rest.convertRestError(errorStack, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.status !== 204 ? await result.json() : undefined;
|
return result.status !== 204 ? await result.json() : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorStack = new Error("Location:");
|
|
||||||
// @ts-ignore Breaks deno deploy. Luca said add ts-ignore until it's fixed
|
|
||||||
Error.captureStackTrace(errorStack);
|
|
||||||
|
|
||||||
// No proxy so we need to handle all rate limiting and such
|
// No proxy so we need to handle all rate limiting and such
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
rest.processRequest(
|
rest.processRequest(
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ if (INFLUX_TOKEN) {
|
|||||||
}, 30000);
|
}, 30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rest.convertRestError = (errorStack, data) => {
|
||||||
|
if (!data) return { message: errorStack.message };
|
||||||
|
return { ...data, message: errorStack.message };
|
||||||
|
};
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
@@ -105,12 +110,7 @@ async function handleRequest(req: Request, res: Response) {
|
|||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
if (error?.code) res.status(500).json(error);
|
res.status(500).json(error);
|
||||||
else {
|
|
||||||
res.status(500).json({
|
|
||||||
error: error.message ?? "No error found at all what the hell discord.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user