mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix: Handle async stacks correctly (#2744)
* fix: Capture stack traces in APIRouter to preserve async stack * fix: Handle the stack trace better * fix: Check if error is an instance of Error (5XX rejects with Result) * fix: Error.captureStackTrace is not supported in all browsers
This commit is contained in:
@@ -11,13 +11,27 @@ function buildRoute(manager) {
|
||||
get(target, name) {
|
||||
if (reflectors.includes(name)) return () => route.join('/');
|
||||
if (methods.includes(name)) {
|
||||
// Preserve async stack
|
||||
let stackTrace = null;
|
||||
if (Error.captureStackTrace) {
|
||||
stackTrace = {};
|
||||
Error.captureStackTrace(stackTrace, this.get);
|
||||
}
|
||||
|
||||
return options => manager.request(name, route.join('/'), Object.assign({
|
||||
versioned: manager.versioned,
|
||||
route: route.map((r, i) => {
|
||||
if (/\d{16,19}/g.test(r)) return /channels|guilds/.test(route[i - 1]) ? r : ':id';
|
||||
return r;
|
||||
}).join('/'),
|
||||
}, options));
|
||||
}, options)).catch(error => {
|
||||
if (stackTrace && (error instanceof Error)) {
|
||||
stackTrace.name = error.name;
|
||||
stackTrace.message = error.message;
|
||||
error.stack = stackTrace.stack;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
route.push(name);
|
||||
return new Proxy(noop, handler);
|
||||
|
||||
Reference in New Issue
Block a user