rozod 6.4.0 → 6.4.1

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.
Files changed (2) hide show
  1. package/lib/index.js +18 -4
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@ const zod_1 = require("zod");
18
18
  const cache_1 = require("./cache");
19
19
  const roblox_bat_1 = require("roblox-bat");
20
20
  const parse_roblox_errors_1 = require("parse-roblox-errors");
21
+ const ROZOD_ERROR = Symbol.for('rozod.error');
21
22
  const endpoint = (endpoint) => {
22
23
  return endpoint;
23
24
  };
@@ -779,8 +780,21 @@ async function fetchApi(endpoint, params, requestOptions = {}) {
779
780
  const contentType = response.headers.get('content-type') ?? '';
780
781
  if (contentType.includes('application/json')) {
781
782
  const json = await response.json();
782
- const jsonMessage = typeof json?.message === 'string' ? json.message : JSON.stringify(json);
783
- parsedError = { message: jsonMessage };
783
+ if (typeof json?.message === 'string') {
784
+ parsedError = { message: json.message };
785
+ }
786
+ else if (typeof json?.error === 'string') {
787
+ parsedError = { message: json.error };
788
+ }
789
+ else if (typeof json?.error_message === 'string') {
790
+ parsedError = { message: json.error_message };
791
+ }
792
+ else if (typeof json?.detail === 'string') {
793
+ parsedError = { message: json.detail };
794
+ }
795
+ else {
796
+ parsedError = { message: JSON.stringify(json) };
797
+ }
784
798
  }
785
799
  else {
786
800
  const text = await response.text();
@@ -791,6 +805,7 @@ async function fetchApi(endpoint, params, requestOptions = {}) {
791
805
  parsedError = { message: response.statusText || `HTTP ${response.status}` };
792
806
  }
793
807
  }
808
+ parsedError[ROZOD_ERROR] = true;
794
809
  if (mergedRequestOptions.throwOnError === true) {
795
810
  throw new Error(parsedError.userFacingMessage ?? parsedError.message);
796
811
  }
@@ -813,8 +828,7 @@ async function fetchApi(endpoint, params, requestOptions = {}) {
813
828
  function isAnyErrorResponse(value) {
814
829
  if (!value || typeof value !== 'object' || Array.isArray(value))
815
830
  return false;
816
- const candidate = value;
817
- return typeof candidate['message'] === 'string';
831
+ return value[ROZOD_ERROR] === true;
818
832
  }
819
833
  /**
820
834
  * Fetches the data from the given endpoint, but splits the request into multiple requests if the specified parameter is larger than max specified.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rozod",
3
- "version": "6.4.0",
3
+ "version": "6.4.1",
4
4
  "description": "A TypeScript wrapper for the Roblox API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",