-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix axios stack traces and upgrade error handler
- Loading branch information
Showing
3 changed files
with
32 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const devLogger = require("@helpers/devLogger"); | ||
const { DiscordAPIError } = require("discord.js"); | ||
|
||
const DEV = process.env.DEV.toLowerCase() == "true"; | ||
|
||
/** | ||
* Handle and log errors | ||
* @author TheRolf, Evorp | ||
* @param {import("discord.js").Client} client discord client | ||
* @param {Error} error error description | ||
* @param {string} type error title | ||
*/ | ||
module.exports = function handleError(client, error, type) { | ||
if (DEV) return console.error(error?.stack ?? error); | ||
|
||
const description = error.stack || JSON.stringify(error); | ||
// if there's no stack, interpret the error as json | ||
const codeBlocks = error.stack ? "" : "json"; | ||
|
||
if (error instanceof DiscordAPIError) | ||
// not on our end | ||
return console.error(error, type, description); | ||
|
||
// silence EPROTO errors | ||
if (error.code == "EPROTO") return console.error(error, type, description); | ||
|
||
// DO NOT DELETE THIS CATCH, IT AVOIDS INFINITE LOOP IF THIS PROMISE REJECTS | ||
devLogger(client, description, { title: type, codeBlocks }).catch(console.error); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters