@webstudio-is/http-client 0.22.0 → 0.24.0

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/lib/cjs/index.cjs CHANGED
@@ -32,22 +32,15 @@ const loadProject = async ({
32
32
  apiUrl,
33
33
  projectId
34
34
  }) => {
35
- try {
36
- if (apiUrl === void 0) {
37
- throw new Error("Webstudio API URL is required.");
38
- }
39
- const baseUrl = new URL(apiUrl);
40
- const projectUrl = new URL(`/rest/project/${projectId}`, baseUrl);
41
- const projectResponse = await (0, import_isomorphic_fetch.default)(projectUrl);
42
- const project = await projectResponse.json();
43
- if (!projectResponse.ok) {
44
- throw new Error(project);
45
- }
46
- return project;
47
- } catch (error) {
48
- if (error instanceof Error) {
49
- return error.message;
50
- }
51
- throw error;
35
+ if (apiUrl === void 0) {
36
+ throw new Error("Webstudio API URL is required.");
52
37
  }
38
+ const baseUrl = new URL(apiUrl);
39
+ const projectUrl = new URL(`/rest/project/${projectId}`, baseUrl);
40
+ const projectResponse = await (0, import_isomorphic_fetch.default)(projectUrl);
41
+ if (projectResponse.ok) {
42
+ return await projectResponse.json();
43
+ }
44
+ const message = await projectResponse.text();
45
+ throw new Error(message.slice(0, 1e3));
53
46
  };
package/lib/index.js CHANGED
@@ -3,24 +3,17 @@ const loadProject = async ({
3
3
  apiUrl,
4
4
  projectId
5
5
  }) => {
6
- try {
7
- if (apiUrl === void 0) {
8
- throw new Error("Webstudio API URL is required.");
9
- }
10
- const baseUrl = new URL(apiUrl);
11
- const projectUrl = new URL(`/rest/project/${projectId}`, baseUrl);
12
- const projectResponse = await fetch(projectUrl);
13
- const project = await projectResponse.json();
14
- if (!projectResponse.ok) {
15
- throw new Error(project);
16
- }
17
- return project;
18
- } catch (error) {
19
- if (error instanceof Error) {
20
- return error.message;
21
- }
22
- throw error;
6
+ if (apiUrl === void 0) {
7
+ throw new Error("Webstudio API URL is required.");
23
8
  }
9
+ const baseUrl = new URL(apiUrl);
10
+ const projectUrl = new URL(`/rest/project/${projectId}`, baseUrl);
11
+ const projectResponse = await fetch(projectUrl);
12
+ if (projectResponse.ok) {
13
+ return await projectResponse.json();
14
+ }
15
+ const message = await projectResponse.text();
16
+ throw new Error(message.slice(0, 1e3));
24
17
  };
25
18
  export {
26
19
  loadProject
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/http-client",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Webstudio HTTP Client",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -11,8 +11,8 @@
11
11
  "jest": "^29.3.1",
12
12
  "typescript": "4.7.4",
13
13
  "@webstudio-is/jest-config": "^1.0.2",
14
- "@webstudio-is/prisma-client": "^0.22.0",
15
- "@webstudio-is/project": "^0.22.0",
14
+ "@webstudio-is/prisma-client": "^0.24.0",
15
+ "@webstudio-is/project": "^0.24.0",
16
16
  "@webstudio-is/scripts": "^0.0.0",
17
17
  "@webstudio-is/tsconfig": "^1.0.1"
18
18
  },
package/src/index.ts CHANGED
@@ -7,23 +7,20 @@ export const loadProject = async ({
7
7
  }: {
8
8
  apiUrl: string;
9
9
  projectId: string;
10
- }): Promise<Array<CanvasData> | string> => {
11
- try {
12
- if (apiUrl === undefined) {
13
- throw new Error("Webstudio API URL is required.");
14
- }
15
- const baseUrl = new URL(apiUrl);
16
- const projectUrl = new URL(`/rest/project/${projectId}`, baseUrl);
17
- const projectResponse = await fetch(projectUrl);
18
- const project = await projectResponse.json();
19
- if (!projectResponse.ok) {
20
- throw new Error(project);
21
- }
22
- return project;
23
- } catch (error) {
24
- if (error instanceof Error) {
25
- return error.message;
26
- }
27
- throw error;
10
+ }): Promise<Array<CanvasData>> => {
11
+ if (apiUrl === undefined) {
12
+ throw new Error("Webstudio API URL is required.");
28
13
  }
14
+ const baseUrl = new URL(apiUrl);
15
+ const projectUrl = new URL(`/rest/project/${projectId}`, baseUrl);
16
+ const projectResponse = await fetch(projectUrl);
17
+
18
+ if (projectResponse.ok) {
19
+ return await projectResponse.json();
20
+ }
21
+
22
+ // In the case where the status code is not 2xx,
23
+ // we don't know what to do with the response other than just show an error message.
24
+ const message = await projectResponse.text();
25
+ throw new Error(message.slice(0, 1000));
29
26
  };