Skip to content

Commit

Permalink
Make errors for discord-arts better
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Jun 5, 2024
1 parent 4afedf4 commit 39b3dbd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
14 changes: 11 additions & 3 deletions patches/@napi-rs+canvas+0.1.52.patch
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
diff --git a/node_modules/@napi-rs/canvas/load-image.js b/node_modules/@napi-rs/canvas/load-image.js
index 09e74f0..5d10642 100644
index 09e74f0..0079ea8 100644
--- a/node_modules/@napi-rs/canvas/load-image.js
+++ b/node_modules/@napi-rs/canvas/load-image.js
@@ -59,6 +59,12 @@ function makeRequest(url, resolve, reject, redirectCount, requestOptions) {
@@ -59,13 +59,19 @@ function makeRequest(url, resolve, reject, redirectCount, requestOptions) {
// lazy load the lib
const lib = isHttps ? (!https ? (https = require('https')) : https) : !http ? (http = require('http')) : http

+ if (url.host === "i.imgur.com") {
+ requestOptions ??= {};
+ requestOptions.headers ??= {};
+ requestOptions.headers.Authorization = process.env.YR_PROXY_AUTH;
+ url = new URL(`https://proxy.yiff.rocks/get?url=${url.href}`);
+ url = new URL(`https://proxy.yiff.rocks/get?url=${url.toString()}`);
+ }
lib
.get(url.toString(), requestOptions || {}, (res) => {
const shouldRedirect = REDIRECT_STATUSES.has(res.statusCode) && typeof res.headers.location === 'string'
if (shouldRedirect && redirectCount > 0)
return makeRequest(new URL(res.headers.location), resolve, reject, redirectCount - 1, requestOptions)
if (typeof res.statusCode === 'number' && (res.statusCode < 200 || res.statusCode >= 300)) {
- return reject(new Error(`remote source rejected with status code ${res.statusCode}`))
+ return reject(new Error(`remote source "${url.toString()}" rejected with status code ${res.statusCode}`))
}

consumeStream(res).then(resolve, reject)
27 changes: 27 additions & 0 deletions patches/discord-arts+0.6.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/node_modules/discord-arts/src/cards/profile-image.js b/node_modules/discord-arts/src/cards/profile-image.js
index 6db3d23..386c8af 100644
--- a/node_modules/discord-arts/src/cards/profile-image.js
+++ b/node_modules/discord-arts/src/cards/profile-image.js
@@ -17,7 +17,7 @@ async function profileImage(userId, options) {
return buffer;
} catch (error) {
if (error.message.includes('source rejected')) {
- throw new DiscordArtsError(`Error loading user assets, try again later`, { userId })
+ throw new DiscordArtsError(`Error loading user assets, try again later`, { userId, cause: error })
}
throw new DiscordArtsError(error?.message, { userId })
}
diff --git a/node_modules/discord-arts/src/utils/error.utils.js b/node_modules/discord-arts/src/utils/error.utils.js
index 1779fdf..b075070 100644
--- a/node_modules/discord-arts/src/utils/error.utils.js
+++ b/node_modules/discord-arts/src/utils/error.utils.js
@@ -1,7 +1,7 @@
class DiscordArtsError extends Error {
constructor(message, info) {
- const { userId, packageVersion } = info;
- super(message);
+ const { userId, packageVersion, cause } = info;
+ super(message, { cause });
this.userId = userId;
}
}
5 changes: 4 additions & 1 deletion src/interactions/applicationCommands/misc/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { profileImage } from "discord-arts";

(global as unknown as { customBadges: Record<string, Array<string> | undefined>; }).customBadges = {
"242843345402069002": ["https://cdn.discordapp.com/emojis/786675436243077140.png"],
"935392548506189884": ["https://cdn.discordapp.com/emojis/1213921250708168814.png"]
"935392548506189884": ["https://cdn.discordapp.com/emojis/1213921250708168814.png"],
"157988109445758976": ["https://cdn.discordapp.com/emojis/1016753364018663514.png"],
"339050872736579589": ["https://cdn.discordapp.com/emojis/994574107574276156.png"],
"738684490787979304": ["https://cdn.discordapp.com/emojis/1177533288861159434.png"]
};
export default new Command(import.meta.url, "rank")
.setDescription("Get a user's rank")
Expand Down

0 comments on commit 39b3dbd

Please sign in to comment.