@xsai/shared 0.4.0-beta.1 → 0.4.0-beta.2

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.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  declare class XSAIError extends Error {
2
2
  response?: Response;
3
- constructor(message: string, response?: Response);
3
+ constructor(message: string, response?: Response, cause?: unknown);
4
4
  }
5
5
 
6
6
  type Fetch = (input: URL, init: RequestInit) => Promise<Response>;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  class XSAIError extends Error {
2
2
  response;
3
- constructor(message, response) {
4
- super(message);
3
+ constructor(message, response, cause) {
4
+ super(message, { cause });
5
5
  this.name = "XSAIError";
6
6
  this.response = response;
7
7
  }
@@ -43,14 +43,14 @@ const responseCatch = async (res) => {
43
43
  return res;
44
44
  };
45
45
 
46
- const responseJSON = async (res) => responseCatch(res).then(async (res2) => {
47
- const text = await res2.text();
46
+ const responseJSON = async (res) => {
47
+ const text = await res.text();
48
48
  try {
49
49
  return JSON.parse(text);
50
- } catch {
51
- throw new Error(`Failed to parse response, response body: ${text}`);
50
+ } catch (cause) {
51
+ throw new XSAIError(`Failed to parse response, response body: ${text}`, res, cause);
52
52
  }
53
- });
53
+ };
54
54
 
55
55
  const trampoline = async (fn) => {
56
56
  let result = await fn();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/shared",
3
3
  "type": "module",
4
- "version": "0.4.0-beta.1",
4
+ "version": "0.4.0-beta.2",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",