@discordjs/rest 3.0.0-dev.1756252917-50018979e → 3.0.0-dev.1756512128-cc43dadca

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -304,7 +304,9 @@ interface RequestData {
304
304
  */
305
305
  appendToFormData?: boolean;
306
306
  /**
307
- * Alternate authorization data to use for this request only, or `false` to disable the Authorization header
307
+ * Alternate authorization data to use for this request only, or `false` to disable the Authorization header.
308
+ * When making a request to a route that includes a token (such as interactions or webhooks), set to `false`
309
+ * to avoid accidentally unsetting the instance token if a 401 is encountered.
308
310
  *
309
311
  * @defaultValue `true`
310
312
  */
package/dist/index.d.ts CHANGED
@@ -304,7 +304,9 @@ interface RequestData {
304
304
  */
305
305
  appendToFormData?: boolean;
306
306
  /**
307
- * Alternate authorization data to use for this request only, or `false` to disable the Authorization header
307
+ * Alternate authorization data to use for this request only, or `false` to disable the Authorization header.
308
+ * When making a request to a route that includes a token (such as interactions or webhooks), set to `false`
309
+ * to avoid accidentally unsetting the instance token if a 401 is encountered.
308
310
  *
309
311
  * @defaultValue `true`
310
312
  */
package/dist/index.js CHANGED
@@ -139,7 +139,7 @@ var import_v102 = require("discord-api-types/v10");
139
139
  // src/lib/utils/constants.ts
140
140
  var import_util = require("@discordjs/util");
141
141
  var import_v10 = require("discord-api-types/v10");
142
- var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1756252917-50018979e)`;
142
+ var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1756512128-cc43dadca)`;
143
143
  var DefaultUserAgentAppendix = (0, import_util.getUserAgentAppendix)();
144
144
  var DefaultRestOptions = {
145
145
  agent: null,
@@ -683,6 +683,7 @@ function normalizeRateLimitOffset(offset, route) {
683
683
  __name(normalizeRateLimitOffset, "normalizeRateLimitOffset");
684
684
 
685
685
  // src/lib/handlers/Shared.ts
686
+ var authFalseWarningEmitted = false;
686
687
  var invalidCount = 0;
687
688
  var invalidCountResetTime = null;
688
689
  function incrementInvalidCount(manager) {
@@ -745,11 +746,21 @@ async function handleErrors(manager, res, method, url, requestData, retries) {
745
746
  throw new HTTPError(status, res.statusText, method, url, requestData);
746
747
  } else {
747
748
  if (status >= 400 && status < 500) {
749
+ const data = await parseResponse(res);
750
+ const isDiscordError = "code" in data;
748
751
  if (status === 401 && requestData.auth === true) {
752
+ if (isDiscordError && data.code !== 0 && !authFalseWarningEmitted) {
753
+ const errorText = `Encountered HTTP 401 with error ${data.code}: ${data.message}. Your token will be removed from this REST instance. If you are using @discordjs/rest directly, consider adding 'auth: false' to the request. Open an issue with your library if not.`;
754
+ if (typeof globalThis.process !== "undefined" && typeof globalThis.process.emitWarning === "function") {
755
+ globalThis.process.emitWarning(errorText);
756
+ } else {
757
+ console.warn(errorText);
758
+ }
759
+ authFalseWarningEmitted = true;
760
+ }
749
761
  manager.setToken(null);
750
762
  }
751
- const data = await parseResponse(res);
752
- throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
763
+ throw new DiscordAPIError(data, isDiscordError ? data.code : data.error, status, method, url, requestData);
753
764
  }
754
765
  return res;
755
766
  }
@@ -1484,7 +1495,7 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
1484
1495
  };
1485
1496
 
1486
1497
  // src/shared.ts
1487
- var version = "3.0.0-dev.1756252917-50018979e";
1498
+ var version = "3.0.0-dev.1756512128-cc43dadca";
1488
1499
 
1489
1500
  // src/index.ts
1490
1501
  setDefaultStrategy((0, import_util2.shouldUseGlobalFetchAndWebSocket)() ? fetch : makeRequest);